AutoFilter

tuongtu3

New Member
Joined
Dec 27, 2018
Messages
5
Hi,
I found the code from this forum and trying to test but got error message:

VBA 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
[COLOR=rgb(184, 49, 47)][B]For Each Itm In aNames   <=== I got error message from this line[/B][/COLOR]
.AutoFilter Field:=1, Criteria1:=Itm

'Do whatever you want with an individual name here

Next Itm
.AutoFilter
End With
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
VBA Code:
aNames = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible).Value

Try modifying like

VBA Code:
aNames = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Value

Are youe sure the code you copied worked for the user who posted it?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,968
Messages
5,767,375
Members
425,409
Latest member
Whatisanexcel

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
Top