|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
首先在Private Sub TextBox3_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)事件中的For i = 2 To .Range("G65536").End(xlUp).Row应该改成For i = 2 To .Range("E65536").End(xlUp).Row
其次,在选择单元格显示文本框后注意要选择一下文本框再进行,因为有时输入到单元格中了,可以考虑把文本框的显示位置移到列表框上面,这样就不会错了.
第三,因为是三列单元格同时需要应用输入时逐步提示信息,所以Private Sub Worksheet_SelectionChange(ByVal Target As Range)事件应该改动一下.显示列表框时加载列表项个人认为还是需要的,输入时可以直接选择后输入.- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- Dim i As Integer
- Me.ListBox1.Clear
- Me.TextBox1 = ""
- Me.ListBox1.Visible = False
- Me.TextBox1.Visible = False
- Me.ListBox2.Clear
- Me.TextBox2 = ""
- Me.ListBox2.Visible = False
- Me.TextBox2.Visible = False
- Me.ListBox3.Clear
- Me.TextBox3 = ""
- Me.ListBox3.Visible = False
- Me.TextBox3.Visible = False
- If Target.Count = 1 And Target.Row > 1 Then
- If Target.Column = 13 Then
- Me.ListBox1.Clear
- Me.TextBox1 = ""
- Me.ListBox1.Visible = False
- Me.TextBox1.Visible = False
- With Me.TextBox1
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left
- .Width = Target.Width
- .Height = Target.Height
- End With
- With Me.ListBox1
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Width = Target.Width
- .Height = Target.Height * 8
- For i = 2 To Sheet8.Range("A65536").End(xlUp).Row
- .AddItem Sheet8.Cells(i, 1).Value
- Next
- End With
- ElseIf Target.Column = 11 Then
- Me.ListBox2.Clear
- Me.TextBox2 = ""
- Me.ListBox2.Visible = False
- Me.TextBox2.Visible = False
- With Me.TextBox2
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left
- .Width = Target.Width
- .Height = Target.Height
- End With
- With Me.ListBox2
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Width = Target.Width + 30
- .Height = Target.Height * 8
- For i = 2 To Sheet8.Range("C65536").End(xlUp).Row
- .AddItem Sheet8.Cells(i, 3).Value
- Next
- End With
- ElseIf Target.Column = 12 Then
- Me.ListBox3.Clear
- Me.TextBox3 = ""
- Me.ListBox3.Visible = False
- Me.TextBox3.Visible = False
- With Me.TextBox3
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left
- .Width = Target.Width
- .Height = Target.Height
- End With
- With Me.ListBox3
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Width = Target.Width + 30
- .Height = Target.Height * 8
- For i = 2 To Sheet8.Range("E65536").End(xlUp).Row
- .AddItem Sheet8.Cells(i, 5).Value
- Next
- End With
- End If
- End If
- End Sub
复制代码 |
|