Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Userform combo box storing data as text 1

Status
Not open for further replies.

Kurupt55

Technical User
Jun 23, 2009
47
NZ
I am new to VBA and am having some trouble with combobox storing numbers as text.
The combobox pulls data from a named range in a sheet containing numbers (stored as numbers)
the user selects a number and then hits a confirm command button with the following code

Private Sub Confirm_Click()

Application.ScreenUpdating = False
Sheets("data").Visible = True

Sheets("data").Range("J1").Value = case1
YourCase.Hide

Sheets("data").Visible = xlVeryHidden
Application.ScreenUpdating = True


End Sub

Case1 is the combobox.
When this puts the data in the cell it returns N/A error with my vlookup in the sheet.
How do i ensure that this is stored as a number compatible with my vlookup

Thanks

Impossible is Nothing
 
Hello,

Comboboxes, dropdowns, etc. all hold values as strings. Use the VAL function to change the combobox value to a number.

Sheets("data").Range("J1").Value = Val(case1)

If you allow a user to input something then you should add a couple of lines of code that check to make sure that the user actually input a number. See IsNumeric in VBA help or the worksheet function IsText in Excel help.
 
Thanks for that, did the trick nicely.
The user will be resticted to choosing one of the options provided, so it will always be a number but thanks for the tip.
Star for you

Impossible is Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top