Data displayed in ComboBox...

kurtc

New Member
Joined
Sep 1, 2011
Messages
30
Morning all, perhaps an easy question here, perhaps i'm being silly. I have a combobox which i have coded to display dynamic info. so it displays info in my A column and will display new info when i add something different.

What i would like it to do though is only display each name in that column once. So at the moment, if someone's name is in the first column and i select it and submit the data, their name will be another option in the drop down.

I would love it to only display each individual name once and not multiple times as the chances are there will be alot of the same name occuring if that makes sense?

The code i am using to make the info appear dynamically is below and i have defined the namelist with the second code

Private Sub UserForm_Initialize()
'Populate Name combo box.
Dim rngName As Range
Dim ws As Worksheet
Set ws = Worksheets("Querylog")
For Each rngName In ws.Range("Namelist")
Me.txtName.AddItem rngName.Value
Next rngName

End Sub

=OFFSET(QueryLog!$A$2:$A$14, 0, 0, COUNTA(QueryLog!$A:$A)-1,1)
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Consider applying finding unique records first from the main column and copy them into another column and then use that to fill the combo.

Here is code for unique records from one column to another. You could then use this when the form is Activated or Initialized.

Sub Macro1()
'
' Macro1 Macro
'

'
Range("E1:E17").Select
Columns("E:E").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Columns( _
"E:E"), CopyToRange:=Range("Q1"), Unique:=True
End Sub
 
Upvote 0
Hi Trevor, thank you very much. Where would i need to put that code? anywhere in the userform or somewhere else?
 
Upvote 0
Place it before it does anything else in the Form Initialize as per your example

Adjust to your columns, ranges etc first though
 
Upvote 0
Trevor, you are a gentleman and a scholar! Works perfectly, have just hidden the columns to tidy the look of it up and applied a filter to display the names alphabetically but here is the code as it is now, with the namelist define code also

Thanks again

Private Sub UserForm_Initialize()
' Macro1 Macro
Range("a1:a17").Select
Columns("a:a").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Columns( _
"a:a"), CopyToRange:=Range("J1"), Unique:=True

'Populate Name combo box.
Dim rngName As Range
Dim ws As Worksheet
Set ws = Worksheets("Querylog")
For Each rngName In ws.Range("Namelist")
Me.txtName.AddItem rngName.Value
Next rngName

End Sub

=OFFSET(QueryLog!$J$2:$J$14, 0, 0, COUNTA(QueryLog!$J:$J)-1,1)
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

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