New to Excel VBA

BryanPayne

New Member
Joined
Feb 19, 2018
Messages
3
Hello everyone!

I have been asked to take a stab at creating a small GUI to look up data vs. Filtering data in excel. The reason I am doing it this way is because I will be summing totals as I click on certain people.

I created a drop-down box (cboSupervisor).
Once I click on a name in the drop-down box, i am needing it to populate the List box (lbManager) with all of the managers that fall under that specific manager.

The supervisor data resides in column E2:E2000. The Managers are listed in column F2:F2000.

I have the Supervisors populating the drop-down list on userform_initialize. The Supervisors name is duplicated so I am removing the duplicates. I havent been able to alphabetize the names either.

ex.

Private Sub UserForm_Initialize()

With Sheets("HoursDetailDateRangeExport").Range("e2:e2000")
v = .Value
End With

With CreateObject("scripting.dictionary")
.comparemode = 1

For Each e In v
If Not .exists(e) Then .Add e, Nothing
Next

If .Count Then Me.cboSupervisor.List = Application.Transpose(.keys)
End With

End Sub


Hopefully someone can get me going in the right direction.

Thanks in advance!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Fluff,

The Supervisors, Managers and Employees are all listed in the spreadsheet by column.

Column B
Employee Last Name

Column C
Employee First Name

Column D
Employee Middle Initial

Column E
Employee Supervisor

Column F
Employee Manager


I have loaded the ComboBox when the UserForm Intitalizes. When the UserForm opens, I select the Supervisor from the dropdown. Once the Supervisor is selected, I am wanting to populate the ListBox with all of the Managers associated with the Supervisor.

This is where I am stuck.
 
Upvote 0
How about
Code:
Option Explicit
Private Dic As Object

Private Sub ComboBox1_Change()
   ListBox1.list = Application.Transpose(Dic(ComboBox1.Value).keys)
End Sub

Private Sub UserForm_Initialize()
   Dim Cl As Range

   Set Dic = CreateObject("scripting.dictionary")
   Dic.comparemode = vbTextCompare
   With Sheets("Sheet3")
      For Each Cl In .Range("E2", .Range("E" & Rows.Count).End(xlUp))
         If Not Dic.exists(Cl.Value) Then
            Dic.Add Cl.Value, CreateObject("scripting.dictionary")
            Dic(Cl.Value).Add Cl.Offset(, 1).Value, Nothing
         ElseIf Not Dic(Cl.Value).exists(Cl.Offset(, 1).Value) Then
            Dic(Cl.Value).Add Cl.Offset(, 1).Value, Nothing
         End If
      Next Cl
   End With
   ComboBox1.list = Application.Transpose(Dic.keys)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
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