Repeated VBA ComboBox Values

ameya

Board Regular
Joined
Jun 10, 2014
Messages
105
Hi, I'm having a little trouble initializing my combobox in excel VBA. Not sure why there are duplicate values for every combobox. Each box displays the items I have added multiple times (ex. MC says 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5).

Also, my dates column, E, has several of the same date. Thus, my comboxbox date values are being repeated too.

Is there any way to display only unique values?
Thanks!

Here is my code
Code:
Private Sub UserForm_Click()
    With Me.Shift
        .AddItem "A"
        .AddItem "B"
        .AddItem "A & B"
    End With
    With Me.MC
        .AddItem "1"
        .AddItem "2"
        .AddItem "3"
        .AddItem "4"
        .AddItem "5"
    End With
    With Me.GraphType
        .AddItem "Bar"
        .AddItem "Line"
        .AddItem "Pie"
    End With
    With Me.InitialDate
        With Worksheets("Calculation")
            InitialDate.List = .Range("E2:E" & .Range("E" & .Rows.Count).End(xlUp).Row).Value
        End With
    End With
    With Me.FinalDate
        With Worksheets("Calculation")
            FinalDate.List = .Range("E2:E" & .Range("E" & .Rows.Count).End(xlUp).Row).Value
        End With
    End With
        
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,
try using the forms Intialize event instead for your code

Code:
Private Sub UserForm_Initialize()
'your code
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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