Excel VBA公式variables查找数据不工作
我通过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)
如果我在Find函数中应用“”,它将起作用:
=RIGHT($B$31,LEN($B$31)-FIND("CA",$B$31)-2)
添加额外的"
我使用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)"
我不完全确定你要用这个公式来做什么,但是如果你想把输出中的引用包括到单元格中,你可以简单地用双引号将它们转义出来。
... FIND(""" & Cells(MyRow1 + 3, 3) & """," & ...