VBA to display distinct values in a combo box

12Rev79

New Member
Joined
Mar 2, 2021
Messages
40
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi Experts,

I have a Combobox1 in my Excel and I tried the code below yet error occur.
The error is Red Font


What I am trying to do from this code are ;
1. to display in my ComboBox1 a Unique values from my Worksheet("Oders") column A
2. Exclude Blanks in the display of Combobox1

Can anyone is kind to help me figure out fixing the error and the code to achieve my needs.
------------------
1618315241419.png


Rich (BB code):
Private Sub ComboBox1_Change()
Dim N, e
With Sheets("Orders").Range("A:A")
    N = .Value
End With
With CreateObject("scripting.dictionary")
    .comparemode = 1
    For Each e In N
        If Not .exists(e) Then .Add e, Nothing
    Next
    If .Count Then Me.ComboBox1.List = Application.Transpose(.keys)
End With
End Sub
-----------------------------

Thanks in advance,
12Rev79
 
Last edited by a moderator:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I get no error.

If e <> "" And Not .exists(e) Then .Add e, Nothing
 
Upvote 0
Solution
Thank you so much mart37, appreciated.
need your advise do I need to post a new thread to make the code display a Distinct value in my combobox1?
or can you help me figure out the code would be?

Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,901
Members
449,097
Latest member
dbomb1414

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