kmmsquared
New Member
- Joined
- Jan 7, 2011
- Messages
- 33
Hi,
I am using the following code to populate a column (the position of this column changes so it is variable i), and then I need to autofilter this column. I keep getting the error "Run-time error '1004': AutoFilter method of Range class failed" on the red line of code below. Any ideas on how to fix this/auto filter column(variable i)?
Thanks!
I am using the following code to populate a column (the position of this column changes so it is variable i), and then I need to autofilter this column. I keep getting the error "Run-time error '1004': AutoFilter method of Range class failed" on the red line of code below. Any ideas on how to fix this/auto filter column(variable i)?
Code:
Sub Vendor_Name()
Dim i As Long
i = Application.WorksheetFunction.Match("Number", Range("1:1"), 0)
Dim lngLastRow As Long
With Sheets("Sheet1")
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Range(Cells(2, i), Cells(lngLastRow, i)).Formula = "=IFERROR(IF(W2=""E"",""Make"",IF(B2=198,""Reference "", IF(B2=510,""Other"",""""))),"""")"
End With
Columns(i).Select
[COLOR=red]Selection.AutoFilter Field = 1, Criteria1 = "="[/COLOR]
End Sub
Thanks!