Excel VBA公式变量查找数据无效
我通过vba应用下面的公式,它会抛出错误Excel VBA公式变量查找数据无效,excel,vba,excel-formula,Excel,Vba,Excel Formula,我通过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)" 我在
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)
要添加额外的“
我使用Chr(34)
将您的公式更改为:
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) & """," & ...