Loop through autofilter

henrik2h

Board Regular
Joined
Aug 25, 2008
Messages
155
Office Version
  1. 2021
Platform
  1. Windows
Hi
I have a table with autofilters. For column A I would like, in VBA, to choose each item one by one until all have been looped through. Is it possible? i.e. choose number one item in the autofilter-list "colA" (without knowing the name of the item), I then do some copy paste of those filtered values to another sheet, next number two on the autofilter-list is choosen and the corresponding filtered values are copied to another place and so on.

Any ideas?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi

See if this helps:

Code:
Sub Sweden()
Dim r%, sh As Worksheet, lastrow%, lc%, i%
Set sh = Sheets("Sheet3")                                           ' source sheet with table at a1:d18
sh.Range("h1") = sh.Range("a1"): sh.Range("h2") = ""                ' the table need headers for advanced filtering
sh.Range("a1:a18").AdvancedFilter xlFilterCopy, sh.Range("h1:h2"), sh.Range("i1"), True ' list items at column I
sh.Activate
lastrow = Evaluate("=match(lookup(2,1/(i:i<>""""),i:i),i:i)")       ' end of column A items, at column I
Sheets("Sheet2").Activate                                           ' destination sheet
lc = Cells(1, Columns.Count).End(xlToLeft).Column
For r = 2 To lastrow                                                ' copy to destination
    sh.Range("h2") = sh.Range("i" & r)                              ' criterion
    sh.Range("a1:d18").AdvancedFilter 2, Range("Sheet3!Criteria"), Cells(1, lc + 5 * r), False
Next
End Sub
 
Upvote 0
Thank you for your efforts. I had to solve it another way but I will try your solution whenever I get the chance.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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