Hi,
I have code in a class module that sets the textboxes to add only numbers:
Public WithEvents TextBoxClass As MSForms.TextBox
Private Sub TextBoxClass_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Then seperate code in the userform for each individual textbox so the user can only input one decimal place:
Private Sub TextBox3_Change()
If IsNumeric(Right(Me.TextBox3.Text, 1)) = False And Right(Me.TextBox3.Text, 1) <> "." And Me.TextBox3.Text <> vbNullString Then
Me.TextBox3.Text = Left(Me.TextBox3.Text, Len(Me.TextBox3.Text) - 1)
Beep
ElseIf Right(Me.TextBox3.Text, 1) = "." Then
Dim CheckDecimal As Integer
Dim DecimalFound As Boolean
CheckDecimal = 1
DecimalFound = False
While CheckDecimal <= Len(Me.TextBox3.Text) - 1 And DecimalFound = False
If Right(Left(Me.TextBox3.Text, CheckDecimal), 1) = "." Then
DecimalFound = True
End If
CheckDecimal = CheckDecimal + 1
Wend
If DecimalFound = True Then
Me.TextBox3.Text = Left(Me.TextBox3.Text, Len(Me.TextBox3.Text) - 1)
Beep
End If
End If
End Sub
What can I put in a class module that negates the need for multiple textbox codes for one decimal place?
I have code in a class module that sets the textboxes to add only numbers:
Public WithEvents TextBoxClass As MSForms.TextBox
Private Sub TextBoxClass_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Then seperate code in the userform for each individual textbox so the user can only input one decimal place:
Private Sub TextBox3_Change()
If IsNumeric(Right(Me.TextBox3.Text, 1)) = False And Right(Me.TextBox3.Text, 1) <> "." And Me.TextBox3.Text <> vbNullString Then
Me.TextBox3.Text = Left(Me.TextBox3.Text, Len(Me.TextBox3.Text) - 1)
Beep
ElseIf Right(Me.TextBox3.Text, 1) = "." Then
Dim CheckDecimal As Integer
Dim DecimalFound As Boolean
CheckDecimal = 1
DecimalFound = False
While CheckDecimal <= Len(Me.TextBox3.Text) - 1 And DecimalFound = False
If Right(Left(Me.TextBox3.Text, CheckDecimal), 1) = "." Then
DecimalFound = True
End If
CheckDecimal = CheckDecimal + 1
Wend
If DecimalFound = True Then
Me.TextBox3.Text = Left(Me.TextBox3.Text, Len(Me.TextBox3.Text) - 1)
Beep
End If
End If
End Sub
What can I put in a class module that negates the need for multiple textbox codes for one decimal place?