Auto Filter column(variable i)

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)?

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!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
They syntax would be:
Code:
Selection.AutoFilter Field:= 1, Criteria1:= "="

Do not try to apply an AutoFilter to a new range until you've removed the autofilter from the prior range.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top