I equate a combo box value to a integer variable in my userform. If i leave the combo box field empty and equate i get run-time error 13. How can i get rid of this problem?
examaple code :
Dim Temp as integer
Temp=CmbBox1.value
I equate a combo box value to a integer variable in my userform. If i leave the combo box field empty and equate i get run-time error 13. How can i get rid of this problem?
examaple code :
Dim Temp as integer
Temp=CmbBox1.value
Temp=int(CmbBox1.value) or Temp=val(CmbBox1.value). Can't remember which it is in VBA.
CmbBox1.value is a string.
Sorry, misread your post. Please ignore
Glen
Hi pico,
moa's code would work, particularly:
[VBA]
Temp=val(CmbBox1.value)
[/VBA]
If it is empty it will default to 0.
Or you could do a preliminary check to see if there's any text in the combo box to begin with:
[VBA]If CmbBox1.Value <> "" Then Temp = CmbBox1.Value[/VBA]
New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.
[vba]
If CmbBox1.ListIndex = -1 Then
Temp = 0
Else
Temp = CmbBox1.Value
End If
[/vba]
Thank you All