Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA公式变量查找数据无效_Excel_Vba_Excel Formula - Fatal编程技术网

Excel 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)" 我在

我通过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)
要添加额外的
我使用
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) & """," & ...