brandon032190
New Member
- Joined
- Dec 15, 2002
- Messages
- 4
Need an ActiveX text box that supports Format masks (i.e.: Date and/or Currency). Apparently, MS-Excel 2000 does not have one. Any ideas?
Dim NewString, MyString, mask As String
Dim position, pos As Variant
Private Sub TextBox1_Change()
If IsNumeric(Right(TextBox1.Text, 2)) And Len(TextBox1.Text) >= 11 Then
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
Else
position = TextBox1.SelStart MyString = TextBox1.Text
pos = InStr(1, MyString, "_")
If pos > 0 Then
NewString = Left(MyString, pos - 1)
Else
NewString = MyString
End If
If Len(NewString) < 11 Then
TextBox1.Text = NewString & Right(mask, Len(mask) - Len(NewString))
TextBox1.SelStart = Len(NewString)
End If
End If
If Len(TextBox1.Text) >= 11 Then
TextBox1.Text = Left(TextBox1.Text, 10)
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
position = TextBox1.SelStart
If KeyCode = 8 Then
TextBox1.Text = mask
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.SelStart = 0
mask = "__.__.____"
TextBox1.Text = mask
End Sub