ComboBox Duplicate Removal?

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I have a combo box on a userform populating via a named range, but I have a lot of N/As in the list and I'd like to remove all the duplicates.

Any suggestions how?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Rather than using a named range, could you build an array looping through the named range and only add the valid entries. You'd then use the array to populate the combobox rather than the named range directly.
 
Upvote 0
Totally willing to do that, but could you advise on how? For example, if the sheet name is "Misc" and I need the range to go from cell A1 to the end of the data set?
 
Upvote 0
This seemed to work from me. Just change the "Name_Of_Range" to suit your situation.


Code:
Private Sub UserForm_Initialize()
Dim str(), foo
Dim k As Long

str = Application.Transpose(Range("Name_Of_Range"))
k = 0
For Each foo In str

    If foo <> "N/A" Then
        Me.ComboBox1.AddItem foo
    End If
Next foo

End Sub
 
Upvote 0
This is one of many ranges I am using. How do I designate this as a column so I can do the same code to set the other ranges in the same way? Many of them currently have duplicates and if this works I'd love to remove them...
 
Upvote 0
Also, the combo box is populated with a different range depending on a radio button being checked first.

In other words, the range can be populated in three different ways: using the indexed # (named range), using an internal company code (second named range) or using the vendor item description (third named range).

The internal description has too many duplicates, but the other two do not. I need to remove the duplicates from the internal range description only....
 
Upvote 0
Here's how I'd populate a combobox based on an option button selection:

Code:
Sub pop_Combobox()
Dim str(), foo
Dim k As Long

k = 0

With UserForm1

    Select Case True
        Case .OptionButton1
            str = Application.Transpose(Range("Name_Of_Range_Associated_with_Option1"))
        Case .OptionButton2
            str = Application.Transpose(Range("Name_Of_Range_Associated_with_Option2"))
        Case .OptionButton3
            str = Application.Transpose(Range("Name_Of_Range_Associated_with_Option3"))
    End Select

    For Each foo In str
        If foo <> "N/A" Then
            .ComboBox1.AddItem foo
        End If
    Next foo

End With

End Sub

Before you were talking about "N/A" values, now you mention duplicates. Are your N/A values duplicates, or do we need to loop through the array and pull out only uniques?
 
Upvote 0
Sorry for the delay, the N/As are duplicates.

Basically we could either. The range is from A1:A180. About 30 of the cells contain actual values, the rest are N/A.

I basically need to pull only the values, not the N/A.
 
Upvote 0
Also, can you interpret what the second line of your code does? I have never seen a dimmed value like that...

I am referring to the line:
Code:
Dim str(), foo

Thanks!!
 
Upvote 0
Then what I posted above should work. The option button that is selected dictates which named range gets used. From there, the range is loaded in as an array, and only non-"N/A" values are put in to the combo box.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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