Wypróbuj taki kod:
Option Explicit
Dim a As Integer
Dim b As String
Dim c As Byte
Dim d As Boolean
Private Sub TextBox1_Change()
If a < 48 Or a > 57 And a < 96 Or a > 105 Then TextBox1.Text = b: TextBox1.SelStart = c
If TextBox1.SelStart = 4 Then TextBox1.SelStart = 5
TextBox1.SelLength = 1
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
a = KeyCode
If TextBox1.SelStart = 4 Then TextBox1.SelStart = 5
TextBox1.SelLength = 1
If Shift = 1 Then a = 1
b = TextBox1.Text
c = TextBox1.SelStart
If TextBox1.SelText = " " Then a = 1
If TextBox1.SelText = "" Then d = False Else d = True
End Sub
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 39 Then c = c + 1: TextBox1_Change
If KeyCode = 37 Then
If TextBox1.SelStart < 1 Then Exit Sub
1
If d = True Then TextBox1.SelStart = TextBox1.SelStart - 1
TextBox1.SelLength = 1
If TextBox1.SelText = " " Then d = True: GoTo 1
End If
End Sub
Private Sub Worksheet_Activate()
TextBox1.MaxLength = 9
b = "#### ####"
TextBox1.Text = b
End Sub
Wklej go do modułu arkusza w którym jest textbox1. We właściwościach textboxu1 ustaw maxlenght = 9 |