|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Private Sub TextBox1_Change()
- With Me.TextBox1
- If VBA.Trim(.Text = "") Then
- .Text = ""
- Me.TextBox2.Text = ""
- Else
- For i = 1 To Len(.Text) '遍历文本框中输入的每一个字符
- Str = VBA.Mid(.Text, i, 1)
- Select Case Str
- Case "a" To "z", "A" To "Z", " ", "-" '列出允许输入的字符
- Case Else
- Beep
- .Text = Replace(.Text, Str, "") '如果输入的不是允许的字符,则使用Replace函数替换成空白
- End Select
- Next i
- Set rng = Sheets("单词表").Range("B:B").Find(.Text, , , 1)
- If Not rng Is Nothing Then
- cr = rng.Offset(0, -1).Resize(1, 3)
- Me.TextBox2.Text = cr(1, 3)
- Me.CommandButton1.Enabled = True
- Me.CommandButton1.Caption = "修 改"
- Else
- Me.TextBox2.Text = ""
- Me.CommandButton1.Enabled = True
- Me.CommandButton1.Caption = "新 增"
- End If
- End If
- End With
- End Sub
复制代码 |
|