创建一个遮罩的文本框

时间:2020-07-04 12:11:55

标签: excel vba

我需要文本框的vba代码才能接受某些位置的字母和某些位置的数字,以其他方式进行限制

我正在尝试将表单链接到Excel工作表。第一个条目是textbox1,它将输入8个字符-前4个仅包含字母,而后一个仅包含数字。建议使用各种人尝试的复制代码来限制输入类型和进行修改。但是失败了。有人可以帮忙吗。

Public counter As Long
'[COLOR="#008000"] [B]
' Note: This Dim statement must be located above any other code procedures[/B][/COLOR]
Public LastPosition As Long
Public lastc As String

Private Sub TextBox1_change()
 Dim s As String
 Dim nlastc As Long
 
 lastc = Asc(Mid(TextBox1.Text, LastPosition, 1))
 MsgBox (lastc)
 Ret = pan_check(lastc, LastPosition, nlastc)
 s = concatenate(s, nlastc)
    
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  LastPosition = TextBox1.SelStart
End Sub

Function pan_check(ByVal lastc As Long, ByVal LastPosition As Long, ByRef new_lastc As Long) As Long
Dim i As Long

i = lastc

If LastPosition < 3 Then

    If i > 64 And C < 91 Then
    new_lastc = i
    Else
    new_lastc = 0
    End If
    If i > 96 And i < 123 Then
    new_lastc = i - 32
    Else
    new_lastc = 0
    End If
Else
End If

If LastPosition > 3 And LastPosition < 8 Then

    If i > 47 And C < 58 Then
    new_lastc = i
    Else
    new_lastc = 0
    End If
Else
End If


End Function

0 个答案:

没有答案