“ Range(” F“&i).Formula =”在字符串中使用iferror时抛出对象定义的错误消息。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
For i = 16 To 194
If Range("O" & i) < 0 Then
answer = MsgBox("Discounted. Are you sure?", vbYesNo)
If answer = No Then
Range("F" & i).Formula = "=iferror(VLOOKUP($B" & i & ",eac_equipment_list!$P:$S,2,FALSE),"")"
End If
If answer = vbYes Then
Range("O" & i) = "0"
End If
End If
Next i
End Sub
有什么想法吗?当我只使用Vlookup而不包含“ iferror”部分时,代码就可以正常工作。
谢谢!
答案 0 :(得分:1)
"=iferror(VLOOKUP($B" & i & ",eac_equipment_list!$P:$S,2,FALSE),"")"
应该是
"=iferror(VLOOKUP($B" & i & ",eac_equipment_list!$P:$S,2,FALSE),"""")"
字符串中的双引号需要加倍以转义