autofilter in loop with vba code

yael zur

New Member
Joined
Nov 6, 2016
Messages
1
hello,
I have table, and on one column I have names.
I would like to create macro, that will autofilter the rows by each possible value in a loop.
For example, if the names are John, Ruth and Hana, the macro will filter once all John rows, then all Ruth's and finally all Hana's (in the loop I'm printing each time the visible rows).
My problem is that the list of name is changing every day, and I don't know how many name will be each time. also the number of rows in the table - is unknown.

I would also like to store each time in the loop the currant filtered value, in order to use this value in formula.

Is it possible to do that?

Help will be most appreciated,

Best Regards,
Yael
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Welcome to the MrExcel board!

You didn't tell us where the names are, so I have assumed column A.

This should loop through each of the unique names in column A. Those names will be stored in the array aNames

Rich (BB code):
Sub LoopEachName()
  Dim aNames As Variant, Itm As Variant
  
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    aNames = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value
    For Each Itm In aNames
      .AutoFilter Field:=1, Criteria1:=Itm
      
      'Do whatever you want with an individual name here
      
    Next Itm
    .AutoFilter
  End With
End Sub
 
Upvote 0
Hi,
I've found the code here but how to modify if I 'd like to autofilter starting at Cell CL13

Regards,
tt3
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,586
Members
449,520
Latest member
TBFrieds

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