VBA autofilter field using dynamic range

jcooooper

Board Regular
Joined
Mar 24, 2018
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hello all,

If I have the following line of VBA, can I make the "AutoFilter Field:=7" number dynamic?



Code:
ActiveSheet.Range("Data_column_headers").AutoFilter Field:=7, Criteria1:="="

Ideally I would place my named range in there as my columns move around.


Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Which named range do you want to use?
If its the named range used for the filter, will it always be the 7th column?
 
Upvote 0
Which named range do you want to use?
If its the named range used for the filter, will it always be the 7th column?

No that's the problem, this data set always moves around....so the named range is dynamic, using the offset function.

The name of the column will always be the same though?
 
Upvote 0
Do you mean that sometimes the data starts in col A & sometimes in column E?
 
Upvote 0
Yep the column will shift around, but its always just a single column wide (it's part of a larger data set).
 
Upvote 0
Are you saying that "Data_column_headers" is a named range 1 column wide?
 
Upvote 0
For example. this is an extract of the data, which actually may be 30 columns wide,

Actually come to think of it I have two questions

The first, how do I filter so that portfolio code = a named range elsewhere (a list of portfolio codes). That named range is dynamic and expand and contracts.

And then the second is that column will move around, so I need a way to dynamically link to that column header to the actual filter

Sorry if this seems complicated



Portfolio NameCountry NameNotional Weight
GB927Germany5.2%
G6008Germany-5.2%
GB908United States0.2%
GB608European Union0.0%
GB928Korea (South), Republic of0.0%
36008United States0.0%
G6008 1.4%
GB928United States-6.4%
GB928United States6.4%
I6008United States0.2%

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Did you see my question in post#6?
 
Upvote 0
Did you see my question in post#6?

ah sorry, appears we posted at the same time and I missed it.

Data_column_headers represents the top row, so portfolio code, country name, notional weight etc. I could potentially fix the row number if that's of any use.
 
Upvote 0
Does that range always start in col A?
What is the named range of the column you want to filter?
 
Upvote 0

Forum statistics

Threads
1,215,328
Messages
6,124,299
Members
449,149
Latest member
mwdbActuary

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