0

'我在 Excel 工作表的单元格 A6 中使用此公式。它工作正常。

=IF(O6="Hand","人工录入",IF(O6="JET",R6,IF(O6="COKE","红牛",IF(O6="货运","物流",IF (O6="TAX","Tax",IF(O6="TRANSFER COST","Transfer Cost Transactions",IFERROR(IF(FIND("INV#",R6,1)>=1,MID(R6,FIND ("INV#",R6,1),10),""),"")))))))

现在,我的问题是:如何将其转换为 VBA?我试过记录下来,代码如下:

ActiveCell.FormulaR1C1 = _ "=IF(RC[14]=""Hand"",""手动输入 JE"",IF(RC[14]=""JET"",RC[17],IF(RC[ 14]=""COKE"",""红牛"",IF(RC[14]=""FREIGHT"",""物流"",IF(RC[14]=""TAX"","" Tax"",IF(RC[14]=""TRANSFER COST"",""Transfer Cost Transactions"",IFERROR(IF(FIND(""INV#"",RC[17],1)>=1, MID(RC[17],FIND(""INV#"",RC[17]" & _ """""),"""")))))))"

当我运行它时,我收到运行时错误 1004:应用程序定义或对象定义的错误。所以我把它改成了这样,除了 find 选项外,这与上面的公式相同,一切运行正常。![VBA For Above formula][Any Help on the find?] End sub.How do I get the fine option in above VBA code.`

4

2 回答 2

1

这对我有用:

Range("L6").Formula = "=IF(O6=""Hand"",""Manual Entry"",IF(O6=""JET"",R6,IF(O6=""COKE"",""Red Bull"",IF(O6=""Freight"",""Logistics"",IF(O6=""TAX"",""Tax"",IF(O6=""TRANSFER COST"",""Transfer Cost Transactions"",IFERROR(IF(FIND(""INV#"",R6,1)>=1,MID(R6,FIND(""INV#"",R6,1),10),""""),"""")))))))"

这只是您原来的 Excel 公式,但"字符转义为"".

于 2013-06-19T14:22:41.063 回答
0

你需要逃避你的报价。

ActiveCell.Formula = "=IF(O6=""Hand"",""Manual Entry"",IF(O6=""JET"",R6,IF(O6=""COKE"",""Red Bull"",IF(O6=""Freight"",""Logistics"",IF(O6=""TAX"",""Tax"",IF(O6=""TRANSFER COST"",""Transfer Cost Transactions"",IFERROR(IF(FIND(""INV#"",R6,1)>=1,MID(R6,FIND(""INV#"",R6,1),10),""""),"""")))))))"

并使用.Formula,因为您使用的特定单元格名称与当前选定的单元格无关。

于 2013-06-19T14:22:32.553 回答