davewatson86
New Member
- Joined
- Jul 8, 2019
- Messages
- 30
Hello all
i am trying to add all the unique values from my range with the below code.
yet i seem to keep getting duplicate values once the user form has been initialized.
my code works through each used cell then checks if the value is in the combobox1.list if not it then ads it to the combobox1
where am i going wrong with my code and is this the most efficient way to do this?
i am at a loss so any help would be greatly appreciated.
regards
Dave
i am trying to add all the unique values from my range with the below code.
Code:
Private Sub UserForm_Initialize()
Dim sngLeft As Single
Dim sngTop As Single
Dim ColNum, i As Integer
Dim Name, myString As String
Dim strFound As Boolean
Call ReturnPosition_CenterScreen(Me.Height, Me.Width, sngLeft, sngTop)
Me.Left = sngLeft
Me.Top = sngTop
ColNum = 0
While Not WS_Data_Dump.Range("K1").Offset(ColNum, 0).Value = ""
Name = WS_Data_Dump.Range("K1").Offset(ColNum, 0).Value
strFound = False
With Me.ComboBox1
'Loop through combobox
For i = 0 To .ListCount - 1
If .List(i) = myString Then
strFound = True
'Exit For
End If
C = C + 1
Next i
'Check if we should add item
If Not strFound Then .AddItem (Name)
End With
ColNum = ColNum + 1
Wend
End Sub
yet i seem to keep getting duplicate values once the user form has been initialized.
my code works through each used cell then checks if the value is in the combobox1.list if not it then ads it to the combobox1
where am i going wrong with my code and is this the most efficient way to do this?
i am at a loss so any help would be greatly appreciated.
regards
Dave