Sort from Combobox

mucah!t

Well-known Member
Joined
Jun 27, 2009
Messages
593
Hello all,

How can I sort a range starting from B6:V6 based on collumn D from a Combobox.

I'd like the the combobox to show all unique names in collumn D so the user can sort the range by selecting one of these names from the Combobox.

Possible?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I already found a solution to fill the combobox with unique values:

Code:
Private Sub Worksheet_Activate()
    Dim c As Range, Coll As New Collection
    On Error Resume Next
    For Each c In Sheets("Urenstaat").[d6:d1000]
        Coll.Add c.Value, c.Value
    Next c
    On Error GoTo 0
    For Each Item In Coll
        Sheets("Urenstaat").ComboBox1.AddItem Item
    Next Item
End Sub

Now I need a way to sort the sheet by selecting one of the items in the combobox.

Ideas?
 
Upvote 0
With the following code I managed to run a macro from the selection

Code:
Private Sub ComboBox1_Change()
Select Case ComboBox1.Value
    Case "Mike"
       Call Mike
    Case "John"
       Call John
    Case "Patrick"
       Call Patrick
       
 End Select
End Sub

The macro's look something like this:

Code:
Sub Mike()
    Range("D9").Select
    Selection.AutoFilter Field:=3, Criteria1:="Mike"
End Sub

It's now working properly.
 
Upvote 0
Still one question.

How can I add an extra item to the list, that isn't in the range?
It should be shown as first item, called "All"

Code:
Private Sub Worksheet_Activate()
    Dim c As Range, Coll As New Collection
    On Error Resume Next
    For Each c In Sheets("Urenstaat").[d6:d1000]
        Coll.Add c.Value, c.Value
    Next c
    On Error GoTo 0
    For Each Item In Coll
        Sheets("Urenstaat").ComboBox1.AddItem Item
    Next Item
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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