Stepping throu advanced filter visible cells = FAIL

Puffin617

New Member
Joined
Nov 13, 2008
Messages
27
I used advanced filter to create a filtered list of unique values in my 3rd column. Now I want to step through them to read them all into an array.

My problem is that is starts off on row 1, skipps row 2 & 3 and continues from 4 correctly...

Please explain this "Area" thing to me:

Code:
Sub Macro5()
Dim QCNameArray(1 To 50) As String

    Columns(3).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Counter = 1
    
    Do While ActiveCell.Value <> ""
        
        ActiveSheet.Columns(3).SpecialCells(xlCellTypeVisible).Areas(Counter).Rows(1).Select
        
        QCNameArray(Counter) = ActiveCell.Value
        Counter = Counter + 1
    Loop
    ActiveSheet.ShowAllData
    
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I don't know if you need me to write the code, but I'd be inclined to filter the data to another location, then you don't have the worry of whether cells are invisible or not.
 
Upvote 0
Alternatively, use this function

Code:
Function unique(ByVal rng As Range) As Variant
    Dim c, v
    With CreateObject("scripting.dictionary")
        For Each c In rng
            v = c.Value
            If Not .exists(v) Then .Add v, 1
        Next c
        unique = WorksheetFunction.Transpose(.keys)
    End With
End Function
If you pass it a range, it will return an array comprised of all the unique values in the range.
 
Upvote 0
If you have already produced a unique filter, then all you need to do is loop through all the cells:
Code:
Sub Macro5()
Dim QCNameArray(1 To 50) As String

    Columns(3).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Counter = 1
    
    For each rngcell in ActiveSheet.Columns(3).SpecialCells(xlCellTypeVisible)
        
        QCNameArray(Counter) = rngCell.Value
        Counter = Counter + 1
    next rngcell
    ActiveSheet.ShowAllData
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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