UserForm Dropdown from another sheet

TimC986

New Member
Joined
Jun 25, 2019
Messages
1
Hello, wondering if someone can help me, I think this will be a relatively simple question for someone.

I have a UserForm with drop downs for Department and Name.

I have an ever growing and changing list of Names in a sheet called ‘Staff Database’. This contains columns Department, Name and Hours.

In my UserForm I’d like to be able to select the department first in the drop down and then it only give me the list of people in that department based on the list in the Staff Database. Then when I click add record it needs to populate Name and Hours in the rows in the relevant sheet for each department (I’ve created one for each department).

I’d be very grateful for the help :)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi & welcome to MrExcel.
How about
Code:
[COLOR=#ff0000]Dim UfDic As Object[/COLOR]

Private Sub ComboBox1_Click()
   Me.ComboBox2.Clear
   Me.ComboBox2.list = UfDic(Me.ComboBox1.Value).Keys
End Sub

Private Sub UserForm_Initialize()
   Dim Cl As Range
   
   Set UfDic = CreateObject("scripting.dictionary")
   With Sheets("Staff Database")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         If Not UfDic.Exists(Cl.Value) Then UfDic.Add Cl.Value, CreateObject("scripting.dictionary")
         UfDic(Cl.Value)(Cl.Offset(, 1).Value) = Empty
      Next Cl
   End With
   Me.ComboBox1.list = UfDic.Keys
End Sub
The line in red must go at the very top of the module, before any code.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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