kapela2017
New Member
- Joined
- Oct 16, 2022
- Messages
- 34
- Office Version
- 365
- Platform
- Windows
First of all best regards VBA engineers, I am currently working on a UserForm that has 7 text boxes, the following is required:
1-That they all update when the event changes active in one of them.
2-That have a numerical format with two decimal places.
1-That they all update when the event changes active in one of them.
2-That have a numerical format with two decimal places.
VBA Code:
The following code is for the number format that is applied to each text box, but I know there is a way to do this by looping through each text box. Only my VBA level is low, many thanks in advance to anyone who can help...
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim s$
Select Case KeyCode
Case VBA.vbKeyBack, VBA.vbKeyDelete
Case VBA.vbKeyDown, VBA.vbKeyUp
Case VBA.vbKeyLeft, VBA.vbKeyRight
Case VBA.vbKeyEnd, VBA.vbKeyHome
Case VBA.vbKeyReturn, VBA.vbKeyTab
Case 48 To 57 '0-9
Case 96 To 105
Case 188, 110, 190: ', .
KeyCode = 188
If InStr(1, TextBox1.Text, ",") > 0 Then KeyCode = 0
Case 109, 189: '-
KeyCode = 0
If InStr(1, TextBox1.Text, "-") = 0 Then
TextBox1.Text = "-" & TextBox1.Text
Else
TextBox1.Text = VBA.Replace(TextBox1.Text, "-", "")
End If
Case Else: KeyCode = 0
End Select
End Sub