2017-08-13 103 views
0

我通過vba應用下面的公式,它會拋出錯誤。Excel VBA公式變量查找數據不起作用

Cells(MyRow1 + 4, 3).Formula = "=RIGHT(" & Cells(MyRow1 + 2, 2).Address & ",LEN(" & Cells(MyRow1 + 2, 2).Address & ")-FIND(" & Cells(MyRow1 + 3, 3) & "," & Cells(MyRow1 + 2, 2).Address & ")-2)" 

我在細胞中得到的輸出是

=RIGHT($B$31,LEN($B$31)-FIND(CA,$B$31)-2) 

如果我申請 「」 在查找功能,它的工作原理:

=RIGHT($B$31,LEN($B$31)-FIND("CA",$B$31)-2) 

回答

1

添加額外的"我使用Chr(34)

更改Formula到:

Cells(MyRow1 + 4, 3).Formula = "=RIGHT(" & Cells(MyRow1 + 2, 2).Address & _ 
          ",LEN(" & Cells(MyRow1 + 2, 2).Address & ")-FIND(" & Chr(34) & _ 
          Cells(MyRow1 + 3, 3) & Chr(34) & "," & Cells(MyRow1 + 2, 2).Address & ")-2)" 
+0

..非常感謝你,它按照你的建議工作 – Manish

0

我不能完全確定你想用這個公式來做些什麼,但如果你想在輸出到單元格的報價,你可以簡單地通過使用雙引號來逃避他們。

... FIND(""" & Cells(MyRow1 + 3, 3) & """," & ... 
+0

謝謝Bro !,上面的建議對我有用! – Manish