|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
原来是表1,现在想修改提取表3的C列3-n行,我改了以后只显前三个,不知道为什么?请大神给看看,哪出错了?
Private Sub UserForm_Initialize()
TextBox1.SetFocus
ComboBox1.ControlTipText = "1" '1才下拉,0不下拉,2TEXTBOX不变动
arr = Sheet3.Range("c3:c" & Range("c65536").End(xlUp).Row)
ComboBox1.List = arr
TextBox2.Text = Date
End Sub
Private Sub ComboBox1_Click() '点击下拉列表项写到文本框
ComboBox1.ControlTipText = "2"
TextBox1 = ComboBox1.Value
ComboBox1.ControlTipText = "0"
End Sub
Private Sub ComboBox1_DropButtonClick() '下拉按钮点击优先于MOUSEUP,如果点下拉就不激活MUOUSEUP事件
ComboBox1.ControlTipText = "0"
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode <> 40 And KeyCode <> 38 And KeyCode <> 13 Then '除回车,上下键外,按让一键都激活文本框,便于输入数据
TextBox1.SetFocus
End If
End Sub
Private Sub ComboBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If ComboBox1.ControlTipText <> "0" Then TextBox1.SetFocus '鼠标点击后激活文本框,这样才能在文本框录入数据
ComboBox1.ControlTipText = "1"
End Sub
Private Sub TextBox1_Change()
If ComboBox1.ControlTipText <> "2" Then '2表示选择了下拉列表项,不触发文本框变动
Dim d
ww = TextBox1
arr = Sheet3.Range("c3:c" & Range("c65536").End(xlUp).Row)
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(arr)
If (InStr(1, arr(i, 1), ww, 1) > 0 Or InStr(1, pinyin(arr(i, 1)), ww, 1) > 0) Then d(arr(i, 1)) = ""
Next
ComboBox1.SetFocus '必须让COMBOBOX先获得焦点
ComboBox1.Clear
ComboBox1.List = d.keys
ComboBox1.DropDown
TextBox1.SetFocus
ComboBox1.DropDown '切回文本框后必须再下拉才行
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If (KeyCode = 40 Or KeyCode = 38 Or KeyCode = 13) And ComboBox1.ListCount > 0 Then '回车,向下箭头,进入下拉列表
ComboBox1.SetFocus
ComboBox1.DropDown
ComboBox1.ListIndex = 0
'SendKeys "{DOWN}" '再发个向下键从组合框文本跳到下拉列表第一条
End If
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
ComboBox1.ControlTipText = "1" '退出文本框允许再次下拉
End Sub
Private Sub TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If ComboBox1.ControlTipText = "1" Then '鼠标移入文本框下拉一次
ComboBox1.DropDown
ComboBox1.ControlTipText = "0" '只下拉一次,避免反复触发
TextBox1.SetFocus
ComboBox1.DropDown '切回文本框后必须再下拉才行
End If
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ComboBox1.ControlTipText = "1" '鼠标移入窗体允许再次下拉
End Sub
Function pinyin(ByVal r As String) As String '查拼音函数
On Error Resume Next
Const hanzi = "啊芭擦搭蛾发噶哈击喀垃妈拿哦啪期然撒塌挖昔压匝ABCDEFGHJKLMNOPQRSTWXYZZ"
Dim i As Long, j As Byte, temp As String
For i = 1 To Len(r)
For j = 1 To 24
If Asc(Mid(r, i, 1)) >= Asc(Mid(hanzi, j, 1)) Then temp = Mid(hanzi, 23 + j, 1)
Next
pinyin = pinyin & temp
Next
End Function
|
|