How to sort unique values in alphabetically order?

Mangolili

Board Regular
Joined
Jun 21, 2011
Messages
54
The code below captures autofilter setting and paste distinct column values onto Values tab. My question is how to sort those values alphabetically? Please help, thanks


Code:
Capture AutoFilter settings
   With WS.AutoFilter
       currentFiltRange = .Range.Address
       With .Filters
           ' don't need operator or criteria2, so just 1 is  enough
           ' ReDim filterArray(1 To .Count, 3)
           intColCount = .Count
           ReDim filterArray(1 To intColCount, 1)
           
           For i = 1 To intColCount
               With .Item(i)
                   If .On Then
                       filterArray(i, 1) = .Criteria1
                       If .Operator Then
                           MsgBox "Only one filter per column please."
                           Exit Sub
                       End If
' debug
' MsgBox filterArray(i, 1)
                   End If
               End With
           Next i
           
            intColCount = .Count
            
           For i = 1 To intColCount
               If filterArray(i, 1) <> "" Then
                   'Paste distinct column values onto Values tab
                    WS.Range(Cells(1, i).Address & ":" & _
                        Cells(1, i).End(xlDown).Address).AdvancedFilter Action:=xlFilterCopy, _
                        CopyToRange:=Sheets("Value").Range("A1"), Unique:=True
               End If
           Next i
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Code:
    With Sheets("Value")
        .Range("A1", .Range("A" & Rows.Count).End(xlUp)).Sort _
                Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
                OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
                DataOption1:=xlSortNormal
    End With
 
Upvote 0
Thanks, alpha frog.

Code:
For i = 1 To intColCount               
 If filterArray(i, 1) <> "" Then                   
       'Paste distinct column values onto Values tab                     
           WS.Range(Cells(1, i).Address & ":" & _                       
                   Cells(1, i).End(xlDown).Address).AdvancedFilter Action:=xlFilterCopy, _                         
           CopyToRange:=Sheets("Value").Range("A1"), Unique:=True                
End If 
              [B]Do I put the code here? [/B]         


 Next i
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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