Sorting numbers accoring to chosen category

KiraJensen

New Member
Joined
May 16, 2018
Messages
8
I have created an excel sheet, where there are two buttons opening two different userforms; one for creating a new project, and one for updating project information.

Some of the informations in these userforms are as an example; ID numbers and project types.

The next step is creating a new userform where the different projects can be viewed on a list.

I therefore have to be able to sort between the different task types, in a userform with two ListBoxes.
1. In the first ListBox the user should be able to select the project type
2. The second ListBox should depend on the first ListBox, where the ListBox should only show the ID numbers which belongs to the chosen project type

The list of ID numbers and Project Types looks something like this:

ID Project Type
10001 Meeting
10002 Development
10003 Support
10004 Design
10005 Construction
10006 Development
10007 Development
10008 Support
10009 Meeting

ect....

Both ListBoxes should also be dynamic due to there constantly being created new project types and ID numbers



Any help would be much appriciated!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi & welcome to MrExcel.
How about
Code:
Option Explicit
Private Dic As Object

Private Sub ListBox1_Click()
Me.ListBox2.Clear
Me.ListBox2.List = Dic(Me.ListBox1.Value).keys
End Sub

Private Sub UserForm_Initialize()
   Dim v1 As String, v2 As String
   Dim Cl As Range
   Set Dic = CreateObject("scripting.dictionary")
   Dic.CompareMode = vbTextCompare
   With Sheets("pcode")
      For Each Cl In .Range("B2", .Range("B" & Rows.Count).End(xlUp))
         v1 = Cl.Value: v2 = Cl.Offset(, -1).Value
         If Not Dic.exists(v1) Then
            Dic.Add v1, CreateObject("scripting.dictionary")
            Dic(v1).Add v2, Nothing
         ElseIf Not Dic(v1).exists(v2) Then
            Dic(v1).Add v2, Nothing
         End If
      Next Cl
   End With
   Me.ListBox1.List = Dic.keys
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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