|
楼主 |
发表于 2014-4-21 23:24
|
显示全部楼层
少如 发表于 2014-4-21 09:11
呵呵! 请您给作一下:
2)如同样要模糊录入,则再建立一个TEXTBOX和一个LISTBOX,套用产品名称模糊查询录 ...
2)在工作表中添加一个TextBox2 和一个ListBox2控件
在代码最前面的代码:
Public Myr&, Arrsj
Dim crr '增加一个公共数组变量
'然后添加以下代码 '(Worksheet_SelectionChange的代码与原来的合并在一起如下):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.ListBox1.Clear
Me.TextBox1 = ""
Me.ListBox1.Visible = False
Me.TextBox1.Visible = False
'新增加代码
Dim i As Integer
Me.ListBox2.Clear
crr = Sheets("客户资料").[A1].CurrentRegion
Me.TextBox2.Value = ActiveCell.Value '将活动单元值赋给文本框
If Target(1).MergeArea.Address = Range("B3").MergeArea.Address Then
With Me.TextBox2
.Visible = True
.Top = Target.Top
.Left = Target.Left
.Width = Target.Width
.Height = Target.Height * 1.2
.Activate
.Text = ""
End With
With Me.ListBox2
.Visible = True
.Top = Target.Top
.Left = Target.Left + Target.Width
.Width = Target.Width * 1.5
.Height = Target.Height * 7
For i = 2 To UBound(crr)
.AddItem crr(i, 3)
Next
End With
Else
Me.ListBox2.Clear
Me.TextBox2 = ""
Me.ListBox2.Visible = False
Me.TextBox2.Visible = False
End If
End Sub
Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim i As Integer
Dim myStr As String
Me.ListBox2.Clear
With Me.TextBox2
For i = 1 To Len(.Value)
myStr = myStr & LCase(Mid$(.Value, i, 1))
Next
End With
For i = 2 To UBound(crr)
If InStr(crr(i, 3), myStr) Then
Me.ListBox2.AddItem crr(i, 3)
End If
Next
End Sub
Private Sub ListBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
ActiveCell.Value = ListBox2.Value
[b4].Select
Me.ListBox2.Clear
Me.TextBox2 = ""
Me.ListBox2.Visible = False
Me.TextBox2.Visible = False
End If
End Sub
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
ActiveCell.Value = ListBox2.Value
[b4].Select
Me.ListBox2.Clear
Me.TextBox2 = ""
Me.ListBox2.Visible = False
Me.TextBox2.Visible = False
End Sub
|
评分
-
1
查看全部评分
-
|