运行时错误1004设置公式属性时应用程序定义或对象定义的错误
这工作正常:
Sub Button1_Click() Dim strFormulas(1 To 3) As Variant With ThisWorkbook.Sheets("TRANSFORM") strFormulas(1) = "=SUM(A2:B2)" strFormulas(2) = "=PRODUCT(A2:B2)" strFormulas(3) = "=A2/B2" .Range("A4:G4").Formula = strFormulas .Range("A4:G20").FillDown End With End Sub
但是这不起作用 – 除了strFormulas(1)
之外,一切都是一样的:
Sub Button1_Click() Dim strFormulas(1 To 3) As Variant With ThisWorkbook.Sheets("TRANSFORM") strFormulas(1) = "=IF(NOT(IMPORT!A4=''),VLOOKUP(IMPORT!A4,'VL1'!$Q$4:$R$26,2,FALSE),'-')" strFormulas(2) = "=PRODUCT(A2:B2)" strFormulas(3) = "=A2/B2" .Range("A4:G4").Formula = strFormulas .Range("A4:G20").FillDown End With End Sub
我得到这个错误:
运行时错误1004应用程序定义或对象定义的错误
我认为这可能是因为我试图从strFormulas(1)
另一个工作表中提取值。
我做了我的研究,找不到解决scheme。 任何人都可以看到问题是什么?
你在strFormulas(1)
里应该有引号的地方有撇号'
,所以应该更像
strFormulas(1) = "=IF(NOT(IMPORT!A4=""""),VLOOKUP(IMPORT!A4,""VL1""!$Q$4:$R$26,2,FALSE),""-"")"
只需用两个引号replace公式中的所有""
。