Link to home
Start Free TrialLog in
Avatar of Mr_Shaw
Mr_Shaw

asked on

VBA Excel...Loop through a filter

I need to loop  through a filter on a column and  select all the cells which are visable.

I am not sure what the values in the filter will be.

I am not sure how to do this.

Does anybody have any idea
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Could you give us a bit more detail? For example, why do you want to select the cells? If it's to copy them to another location, then you should be able to just select and copy the whole data block and only the visible cells will be copied.
Avatar of Mr_Shaw
Mr_Shaw

ASKER

Ok..For each iteration of the loop I would like to

select first/next item from filter.
Select cells
Run a macro

The values in the column which I will be filtering on change it month.
Oh I see what you mean. There is no programmatic access to the contents of the filter drop down so you would have to loop through all the data and create a unique list of items and then apply each of those to the filter. Can you elaborate as to what this macro is that you want to run on each set of cell - there may be an easier way to achieve your end goal.
Avatar of Mr_Shaw

ASKER

In detail the whole loop would need to do:

select first/next item from filter.
Select cells
export the selected cells to a new Excel file
Can you post a sample workbook showing the data layout and tell us which field(s) you want to filter on and what you want the new workbooks to be called?
Avatar of Mr_Shaw

ASKER

Might be easier if I ask you specif questions.

at the moment filter I have to specify the value. For example:

Selection.AutoFilter Field:=1, Criteria1:="Shop1"

Is there anything which would allow me to filter on the first item in the filter dropdown list.

For example:

Selection.AutoFilter Field:=1, Criteria1:=1
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Shaw

ASKER

What do you need to know about my layout
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rowcount needs to be defined btw, like with

rowcount = Range("A65536").End(xlUp).Row

which should come AFTER the two filters are done, but before the copy.
Where is the data (sheet and columns), and which column are you filtering on?
Avatar of Mr_Shaw

ASKER

I am filtering on sheet1 and column A
Avatar of Mr_Shaw

ASKER

thanks