我精确复制了MSDN中的代码: sample-user-defined-function-to-hide-formula-errors-in-excel
我试图放入一系列细胞的公式是:
Selection = "=IFError(INDEX(Data_Import!$B$2:$R$16, MATCH(Reg!$B4,
Data_Import!$A$2:$A$16,0),Reg!C$3), "n/a" )"
但我在语法
中收到错误消息我做错了什么?编译错误:
预期:声明结束
我的子代码是:
Sub PresentDat(Wks As Integer)
Dim x, LenWks As Long
Dim Y As Variant
Worksheets(5).Activate
Range("B26").CurrentRegion.Select
x = Selection.Columns.Count - 1
Worksheets(Wks).Activate
Sheets(Wks).UsedRange.Find("Element").Select
LenWks = Range(Selection, Selection.End(xlDown)).Rows _
.Count - 1 Selection.Offset(1, 1).Resize(LenWks, x).Select
Selection.Formula = "=INDEX(Data_Import!$A$1:$R$65,
MATCH($B23,Data_Import!$A$1:$A$65,0), COLUMN(C23)-1)"
Sheets(Wks).UsedRange.Find("No.").Select
LenWks = Range(Selection, Selection.End(xlDown)).Rows _
.Count - 4
Selection.Offset(1, 1).Resize(LenWks, x).Select
Selection = "=IFError(INDEX(Data_Import!$B$2:$R$16, MATCH(Reg!$B4, Data_Import!$A$2:$A$16,0),Reg!C$3), )"
End Sub
我无法让它在单元格中输入我想要的错误消息:c。 。 谢谢!
答案 0 :(得分:1)
根据显示的顶部公式,您需要使用“”来转义内部“”,以便整个公式不会引发错误,即""n/a""
= "=IFError(INDEX(Data_Import!$B$2:$R$16, MATCH(Reg!$B4,Data_Import!$A$2:$A$16,0),Reg!C$3), ""n/a"")"