Creating a List of Unique Values for a Combobox Rowsource

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

I am using the code below to take the values in column G (starting at G6) of worksheet "LISTS1" to create the rowsource for combobox "cb_league1" in my userform.

Code:
    With Worksheets("LISTS1")
        Set Rng = .Range("G6", .Range("G6").End(xlDown))
    End With
    For Each cell In Rng.Cells
        With Me.cb_league1
            .AddItem cell.Value
            .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
            .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
        End With
    Next cell

It works, but I would like to enhance it (if possible) to use only unique values in the rowsource. With the code I get now, I am getting multiple instances of the same value, which is unnecessary.
 
Hey David ... yeah ... error testing always seems to to be most work to figure out for me and I have been playing around in between our posts to come up with very awkward ways of doing this. Some work, some don't, others just lead to more questions ... perhaps there is a more advanced and efficient way of doing things beyond my scope.

Here's the scenario of how a user will use this userform.

The database (DATA) hold a listing of all our current usergroups (League) and their different programs (programs). When a group wishes to use a field, they are issued a permit. This userform prepares the permit based on the information that has is in the database. So, when say a WMGSA Novice Rep softball team wishes to have a permit, the permit issuer (the one using the userform with limited knowledge of the needs of the usergroup) user the form to drill down to find the default setup information already on hand. lb_sport1 = Softball, lb_calibre 2 = REP, cb_league1 = WMGSA and cb_program1 = Novice. The remainder of the permit fields relating to setup for this group are already known (from referencing that row in the database) and the fields of the permit are applied automatically. The permit issuer does not need to know anything except the customer information on record to get the setup details.

Now consider a new REP softball league wishing a permit, one that is not in the database. They will not have any default data to populate the permit. Lets consider a new group "TCWSA". Permit issuer lb_sport1 = softball, lb_calibre1 = REP. Now, the way we have it set up currently, is the league will populate only with "WMGSA", which we don't want. At this point we want the permit issuer to enter the new TCWSA into the cb_league1. Now, of course the filter criteria for this will fail as their is now data. The permit issuer will now be required to manually enter cb_program1 as there is nothing (hopefully) to select from. There is no record for this new submission, so the permit fields will not auto populate and will have to be manually entered, unlike when a record exists.

Please don't spend a lot of time on this David, I will more than understand with thanks for knowledge and direction you've already given. This is more a learning process for me than anything practical at this point, and I've been trying different techniques to accomplish a final product. The guidance and suggestions are more than enough, the actual code is a bonus! As I said, I think I can accomplish what I need in a very inefficient and primitive way.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,532
Messages
6,172,875
Members
452,486
Latest member
standw01

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