|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Private Sub ListBox1_Click()
- ActiveCell.Value = ListBox1.Value
- Me.TextBox1.Visible = False
- Me.ListBox1.Visible = False
- End Sub
- Private Sub TextBox1_Change()
- Me.ListBox1.Clear
- Dim arr
- arr = Sheet1.Range("d1").CurrentRegion.Value
- s = TextBox1.Value
- If Len(s) < 1 Then Exit Sub
- s1 = Left(Trim(s), 1)
- x = 0
- iA = Asc(s1)
- If (iA >= 65 And iA <= 90) Or (iA >= 97 And iA <= 122) Then
- x = 1
- Else
- x = 0
- End If
- If x Then
- For i = 1 To UBound(arr)
- If arr(i, 2) Like "*" & s & "*" Then
- Me.ListBox1.AddItem arr(i, 1)
- End If
- Next
- Else
- For i = 1 To UBound(arr)
- If arr(i, 1) Like "*" & s & "*" Then
- Me.ListBox1.AddItem arr(i, 1)
-
- End If
- Next
- End If
- If Len(s) >= 3 And Me.ListBox1.ListCount < 1 Then
- yy = MsgBox("您是否添加此数据", vbYesNo, "提示")
- If yy = 6 Then
- tt = VBA.Right(Trim(s), 2)
- tt = VBA.LCase(Py$(tt))
- Set rng = Me.Cells(Rows.Count, "d").End(3)
- rng.Offset(1, 0) = s: rng.Offset(1, 1) = tt
- Me.TextBox1.Visible = False
- Me.ListBox1.Visible = False
- End If
-
- End If
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then
- Me.TextBox1.Visible = False
- Me.ListBox1.Visible = False
- Exit Sub
- End If
- With Me.TextBox1
- If Target.Column = 1 Then
- .Value = ""
- .Visible = True
- .Left = Target.Left + Target.Width
- .Top = Target.Top
- .Height = Target.Height
- .Width = ListBox1.Width
- With Me.ListBox1
- .Left = Target.Left + Target.Width
- .Top = Target.Top + Target.Height
- .Visible = True
- End With
- Else
- .Visible = False
- Me.ListBox1.Visible = False
- End If
-
- End With
- End Sub
- Function Py$(ByVal rng$)
- Dim i%, pyArr, str$, ch$
- pyArr = [{"吖","A";"八","B";"攃","C";"咑","D";"妸","E";"发","F";"旮","G";"哈","H";"丌","J";"咔","K";"垃","L";"妈","M";"乸","N";"噢","O";"帊","P";"七","Q";"冄","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"}]
- str = Replace(Replace(rng, " ", ""), " ", "") '去空格和Tab
- For i = 1 To Len(str)
- ch = Mid(str, i, 1)
- If ch Like "[一-龥]" Then '如果是汉字,进行转换
- Py = Py & WorksheetFunction.Lookup(Mid(str, i, 1), pyArr)
- Else
- 'Py = Py & UCase(ch) '如果不是汉字,直接输出
- End If
- Next
- End Function
复制代码 |
|