当我运行下面的macros时,我得到“运行时错误”1004“:应用程序定义或对象定义的错误。

我是这个新手。 我相信这是语法相关的。 感谢任何帮助! 奇怪的是,我有相同的代码在同一工作簿中的另一个模块中工作。 我把它复制到这个macros,并简单地改变了单元格引用。

debugging突出显示了开始的代码行…“Range(”O2:O“&EndRow)”。

Excelmacros代码:

Sub insertsubmissionformulas() ' ' insertsubmissionformulas Macro ' Sheets("Client").Select With ThisWorkbook.Worksheets("Client") EndRow = .Cells(.Rows.Count, "N").End(xlUp).Row Range("O2:O" & EndRow).Formula = "=IF(ISBLANK(N2),"",INDEX(Historical!$C:$C,MATCH(N2,Historical!L:L,0)))" End With ' End Sub 

您需要四个引号才能在空白处显示双引号,而不是两个。 "=IF(ISBLANK(N2),"""",INDEX(Historical!$C:$C,MATCH(N2,Historical!L:L,0)))"