I am running in a little snag in my program. I have a very large database of values. I want to read in unique values from a specific column into a combobox. I am using the following code to populate the combobox.
this will go through every row and read the value in column K then compare it to the values previously stored in the combobox. If it is unique it will be added. If it is not unique it is skipped.
The problem.
When the values in cell (x,11) are numeric the code does not perform the test correctly. It treats combobox value as a text and the cell value as a number(even it has a cell format=text). Therefore when the comparison it done it will yield
ws.Cells(x, 11) = 5
Me.num_single.List(y - 1) = "5"
and then it will add the value to the combobox again. Is there a way to treat the cell value as a test so that the above test will be true.
Code:
If Me.num_single.ListCount <> 0 Then
For y = 1 To Me.num_single.ListCount
If ws.Cells(x, 11) = Me.num_single.List(y - 1) Then Exit Sub
Next y
End If
With Me.num_single
.AddItem ws.Cells(x, 11)
End With
this will go through every row and read the value in column K then compare it to the values previously stored in the combobox. If it is unique it will be added. If it is not unique it is skipped.
The problem.
When the values in cell (x,11) are numeric the code does not perform the test correctly. It treats combobox value as a text and the cell value as a number(even it has a cell format=text). Therefore when the comparison it done it will yield
ws.Cells(x, 11) = 5
Me.num_single.List(y - 1) = "5"
and then it will add the value to the combobox again. Is there a way to treat the cell value as a test so that the above test will be true.