VBA Multi Column Dictionary Key into Combobox

neb255

Board Regular
Joined
Sep 14, 2011
Messages
64
Hi,

I have the below snippet of code which is creating a unique list for a combobox on a form. It works very well to provide me the unique list of values from column "U," however I would like to include the associated Values from column "M." I have read through a number of posts on this topic but cant seem to get it to work for me.

I dont know if this is possible since I need the selected value from the userform combobox to be used as a filter on column "U" in a later section of code.

Can someone please help me revise this?

I appreciate any help :)


Code:
Private Sub UserForm_Activate()
            
            Application.ScreenUpdating = False

Dim rng As Range
Dim Dn As Range
Dim Dic As Object
      
Set rng = Range(Sheets("Subscription").Range("U2"), Sheets("Subscription").Range("U" & Rows.Count).End(xlUp))
    Set Dic = CreateObject("scripting.dictionary")
        Dic.CompareMode = vbTextCompare
For Each Dn In rng
  If Not Dn = vbNullString Then Dic(Dn.Value) = Empty
Next
With UserForm1.ComboBox1
    .Columncount = 2
    .RowSource = ""
    .List = Dic.Keys
    .ListIndex = 0
End With

Here is the later code which uses the combobox selection as a filter incase this makes a difference:
Code:
Dim lasta As Long
lasta = Sheets("Subscription").Range("a" & Rows.Count).End(xlUp).Row

    Range("A1:U" & lasta).AutoFilter Field:=21, Criteria1:=UserForm1.ComboBox1.Value
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
How should values from M be included in the combobox? Like "U1 - M1", "U2 - M2", ... , "Un - Mn" or U1, U2, ..., Un, M1, M2, ... , Mn?
 
Upvote 0
You need to update the loop in UserForm_Activate:

Code:
For Each Dn In rng
      If Not Dn = vbNullString Then Dic([COLOR=#0000ff]Dn.Value & "-" & Sheets("Subscription").Range("M" & Dn.Row)[/COLOR]) = Empty
Next

And then later retrieve column U values from it as:
Code:
Range("A1:U" & lasta).AutoFilter Field:=21, Criteria1:=[COLOR=#0000ff]Split(UserForm1.ComboBox1.Value, "-")(0)[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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