Sunday, June 19, 2016

EXCEL VBA: How to convert a Textbox value in number

The textbox always return a string, you have to use one of the function below to convert it to the format you want:

CBool(expression)CByte(expression)CChar(expression)CDate(expression)CDbl(expression)CDec(expression)CInt(expression)CLng(expression)CObj(expression)CSByte(expression)CShort(expression)CSng(expression)CStr(expression)CUInt(expression)CULng(expression) 
CUShort(expression) 


Example if we want to multiply by 2 the number entered in Textbox1:


Private Sub CommandButton1_Click()
a = CInt(TextBox1.Value)
MsgBox ("If we multiply Textbox1 value by 2, the result is: " & a * 2)
End Sub

No comments:

Post a Comment