Items in combobox added with condition of another combobox

tiger837

New Member
Joined
Dec 3, 2018
Messages
8
Hi everyone,

I have a problem for a userform which uses comboboxes.
So basically I have column A with "area" items and column B with "process" items. I don't know how many different items I have in theses columns. But everytime you have an area, you have a process written next to it.
I want a userform with a first combobox that will allow us to choose a area written in column A. Even if the area is named multipled times, it will be displayed only once on the combobox. Furthermore, all areas in the combobox are sorted A->z.
I have written this code that is working, but I can't sort the areas a->Z.

Code:
Private Sub Userform_Initialize()
    Dim j As Integer
    
    For j = 4 To Range("A65536").End(xlUp).Row
        AreaBox = Range("A" & j)
        If AreaBox.ListIndex = -1 Then AreaBox.AddItem Range("A" & j)
    Next j
    
End Sub

After that, I want a 2nd combobox that will list the process items that exist for the area choosen. Like for the first combobox, each process items will appeared only once, and sorted a->z.
It's for this combobox that I have more trouble because with the following combobox, all processes appeared even if they don't exist for the selected area.
Code:
Private Sub AreaBox_change()


    Dim r As Range
    Dim c As Range
    
    Set r = Range("A4:A200")


    For Each c In r
        If c.Value = AreaBox.Value Then
            ProcessBox.AddItem c.Offset(0, 1).Value
            If ProcessBox.ListIndex = -1 Then ProcessBox.AddItem c.Offset(0, 1)
        End If
    Next c


End Sub

If anyone have a solution for theses problems, I'll be glad to ear it ! Thanks :)
 
You're welcome & thanks for the feedback
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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