Using a named range in autofilter Field

mecerrato

Board Regular
Joined
Oct 5, 2015
Messages
174
Office Version
  1. 365
Platform
  1. Windows
I use autofilter for a bunch of things from corporate reports. However, every now and then corporate changes the fields around which messes up my macros. If I am able to use named ranges instead of column numbers in the autofilter code I can fix really easy by just changing the column referenced in the name range.

Sheets("Current Pipeline").Range("$A$1:$AI$150000").AutoFilter Field:=4, Criteria1:=LC

I haven't been able to find a way to do it, any thoughts?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Maybe
VBA Code:
Sheets("Current Pipeline").Range("$A$1:$AI$150000").AutoFilter Field:=Range("MyField").Column, Criteria1:=LC
 
Upvote 0
Do they change the names of the headers as well, or just change the order?
 
Upvote 0
I was able to make it work using this code from stackoverflow forum:

VBA Code:
Dim LC As String
Dim LOcIndex As Long
LC = Sheets("Summary").Range("B21").Value
LOcIndex = Application.Match("LO", Sheets("Current Pipeline").Range("A1:AK1"), 0)
Sheets("Current Pipeline").Range("$A$1:$AI$150000").AutoFilter Field:=LOcIndex, Criteria1:=LC
 
Upvote 0
Solution
Cross posted at: Using a named range in autofilter Field

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.
Be sure to follow & read the link at the end of the rule too!

If you have posted the question at more places, please provide links to those as well.
If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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