I copied precisely the codes from MSDN: sample-user-defined-function-to-hide-formula-errors-in-excel
The formula I'm trying to put in a range of cells is:
Selection = "=IFError(INDEX(Data_Import!$B$2:$R$16, MATCH(Reg!$B4,
Data_Import!$A$2:$A$16,0),Reg!C$3), "n/a" )"
But I am getting an error message in the syntax
Compile error:
Expected: end of statement
what am I doing wrong?
my sub code is:
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
I just can't get it to put in the error message I want in the cells, :c . . Thanks!