VBA - Using Range Names Instead of Column Numbers

350Z Pilot

Board Regular
Joined
Nov 18, 2008
Messages
64
I am trying to use a Range Name instead of a Column# (Field#)

Instead of this:
Application.Goto Reference:="Sheet1"
ActiveSheet.Range("$A$1:$GZ$999999").AutoFilter Field:=137, Criteria1:="Y"

I would like to use a Range Name like this:
Application.Goto Reference:="Sheet1"
ActiveSheet.Range("$A$1:$GZ$999999").AutoFilter Field:="T_Restricted_List", Criteria1:="Y"

My columns can be moved without my knowledge so a macro using a Column Count is vulnerable. A Range Name will move with the columns in a predictable manner.

Thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try...

Code:
ActiveSheet.Range("$A$1:$GZ$999999").[B]AutoFilter Field:=Range("T_Restricted_List").Column[/B], Criteria1:="Y"

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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