ChangeWorld
ChangeWorld

Reputation: 431

Fill combobox with only numbers

Hello I have this Excel Spreadsheet

enter image description here

I would like to fill my combobox ComboBox1 only with the numbers in the given range.

So far I used this code to fill a combobox

With Worksheets("mySheet")
   ComboBox1.List = .Range("A1", .Range("A" & Rows.Count).End(xlUp)).Value
End With

But this function fills my Combobox with all the values. Is there a way to make ComboBox recognize only numbers?

Edit:

With the isNumeric() worked nice but it inserts blank spaces like the picture below

enter image description here

Thank you in advance.

Upvotes: 0

Views: 487

Answers (1)

shrivallabha.redij
shrivallabha.redij

Reputation: 5902

You can add a check like below.

For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
     If IsNumeric(Range("A" & i).Value) And Range("A" & i).Value <> "" Then ComboBox1.AddItem Range("A" & i).Value
Next i

Upvotes: 1

Related Questions