comparison of combobox value and spreadsheet number

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
350
Office Version
  1. 365
Platform
  1. Windows
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.

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.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try:-
Code:
If ws.Cells(x, 11) = [COLOR=red][B]Val([/B][/COLOR]Me.num_single.List(y - 1)[COLOR=red][B])[/B][/COLOR] Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,550
Members
452,927
Latest member
rows and columns

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