当我拿出IFERROR时,我的代码有效,但当它在那里时,我得到运行时错误1004。
任何人都知道为什么?
Sub datacleanup()
Dim masterBook As Excel.Workbook
Dim dataSht As Worksheet
Dim rowLength As Integer
Dim ctrlPnl As Worksheet
Application.ScreenUpdating = False
Set masterBook = Excel.Workbooks("Working - Vendor Document Status Report.xlsm")
Set dataSht = masterBook.Worksheets("Data")
Set ctrlPnl = masterBook.Worksheets("Controlpanel")
dataSht.Activate
rowLength = dataSht.Range("A3").End(xlDown).Row
With Range("B3:B" & rowLength)
.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],Controlpanel!R2C1:R100C6,3,False),"")"
.Value = .Value
End With
Application.ScreenUpdating = True
End Sub
干杯
答案 0 :(得分:1)
您必须使用“”
在公式字符串中转义value-if-error
双引号(“”)的=IFERROR
部分
更改
"=IFERROR(VLOOKUP(RC[-1],Controlpanel!R2C1:R100C6,3,False),"")"
到
"=IFERROR(VLOOKUP(RC[-1],Controlpanel!R2C1:R100C6,3,False),"""")"