Hello Excel VBA experts,
I have created a textbox (activex control) that I would like to work with my calculation. Notice that, the code below, I want users to enter only numerical numbers (including decimals...e.g. 25.50) and if it's really numerical, the textbox will show it in percentage format with 2 decimal places (e.g. 25.50%). However, whenever I try to type it more than 2 digits, it always goes to the 2nd IF statement where the msgbox is. The reason too why I want it to be a 'change' event so that I could see instantly of the calculation when the user input whatever numbers.
Your help is greatly appreciated!
Private Sub TextBox_MCDDisc_Change()
With Me.TextBox_MCDDisc
If Len(Me.TextBox_MCDDisc) = 0 Then
.Value = vbNullString
ElseIf Len(Me.TextBox_MCDDisc) >= 1 And Not IsNumeric(.Value) Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
Else
.Text = Format(.Value / 100, "0.00%")
Range("A1").Value = TextBox_MCDDisc.Value
End If
End With
End Sub
Bookmarks