|
楼主 |
发表于 2013-3-12 08:44
|
显示全部楼层
leilay 发表于 2013-3-11 22:42
改了,虽然是实现了,不过还是有个小bug
就是选中后那个框会显示绿色。要点一下才会显示内容。
改成这样就可以了,哈。乱来的。不知道有没有问题就是。- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- Dim i As Integer
- Me.ListBox1.Clear
- Arr = Sheet2.[a1].CurrentRegion
- Me.TextBox1.Value = ActiveCell.Value '将活动单元值赋给文本框
- If Target.Count = 1 Then
- If Target.Column = 1 And Target.Address <> "$A$1" Then
- With Me.TextBox1
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left
- .Width = Target.Width
- .Height = Target.Height
- .Activate
- .Text = ""
- End With
- With Me.ListBox1
- .Visible = True
- .Top = Target.Top
- .Left = Target.Left + Target.Width
- .Width = Target.Width + 30
- .Height = 140
- For i = 2 To UBound(Arr)
- .AddItem Arr(i, 1)
- Next
- End With
- Else
- Me.ListBox1.Clear
- Me.TextBox1 = ""
- Me.ListBox1.Visible = False
- Me.TextBox1.Visible = False
- End If
- End If
- End Sub
- Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- Dim i As Integer
- Dim myStr As String
- Me.ListBox1.Clear
- With Me.TextBox1
- For i = 1 To Len(.Value)
- myStr = myStr & LCase(Mid$(.Value, i, 1))
- Next
- End With
- For i = 2 To UBound(Arr)
- If InStr(Arr(i, 1), myStr) Then
- Me.ListBox1.AddItem Arr(i, 1)
- End If
- Next
- End Sub
- Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- If KeyCode = vbKeyReturn Then
- ActiveCell.Value = ListBox1.Value
- Me.ListBox1.Clear
- Me.TextBox1 = ""
- Me.ListBox1.Visible = False
- Me.TextBox1.Visible = False
- End If
- End Sub
- Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
- ActiveCell.Value = ListBox1.Value
- Me.ListBox1.Clear
- Me.TextBox1 = ""
- Me.ListBox1.Visible = False
- Me.TextBox1.Visible = False
- End Sub
复制代码 |
|