|
全部代码在这儿,供参考:
- Option Explicit
- Dim Rng As Range, arr(), i%, j%
- Dim Item As MSComctlLib.ListItem, n%
- Private Sub ComboBox1_Change()
- n = 0: Erase arr
- ListView1.ListItems.Clear
- If ComboBox1.Text = "全部" Then
- For i = 1 To Sheet7.Range("A1").CurrentRegion.Columns.Count Step 5
- Set Rng = Sheet7.Cells(4, i)
- ListItemAdd
- Next
- Else
- Set Rng = Sheet7.Range("A1").CurrentRegion.Find(ComboBox1.Text, LookAt:=xlWhole).Offset(3, -3)
- ListItemAdd
- End If
- End Sub
- Private Sub ListItemAdd()
- If Not Rng Is Nothing Then
- Do While Rng.Value <> ""
- Set Item = ListView1.ListItems.Add
- n = n + 1: ReDim Preserve arr(1 To 5, 1 To n)
- Item.Text = n 'Rng.Value
- arr(1, n) = n
- For j = 1 To 4
- Item.SubItems(j) = Rng.Offset(0, j).Value
- arr(j + 1, n) = Rng.Offset(0, j).Value
- Next
- Set Rng = Rng.Offset(1, 0)
- Loop
- End If
- End Sub
- Private Sub ListView1_DblClick()
- Rem 改为双击比较好些
- ActiveCell.Value = Item.ListSubItems(1)
- ActiveCell.Offset(0, 2).Value = Item.ListSubItems(2)
- ActiveCell.Offset(0, 1).Activate
- Unload UserForm1
- End Sub
- Private Sub TextBox1_Change()
- n = 0
- ListView1.ListItems.Clear
- If TextBox1.Text = "" Then Exit Sub
- For i = 1 To UBound(arr, 2)
- If arr(2, i) Like "*" & TextBox1.Text & "*" Then
- Set Item = ListView1.ListItems.Add
- n = n + 1
- Item.Text = n
- For j = 2 To 5
- Item.SubItems(j - 1) = arr(j, i)
- Next
- End If
- Next
- End Sub
- Private Sub UserForm_Initialize()
- With ListView1
- .ColumnHeaders.Add , , "编号", 28 '添第一列表头,宽度为60
- .ColumnHeaders.Add , , "名称", 90 '添第二列表头,宽度为55
- .ColumnHeaders.Add , , "单位", 40 '添第三列表头,宽度为55
- .ColumnHeaders.Add , , "报价", 60 '添第三列表头,宽度为55
- .ColumnHeaders.Add , , "议价", 60 '添第三列表头,宽度为55
- .View = lvwReport
- .Gridlines = True '显示网格线
- .FullRowSelect = True
- .Font.Size = 10
- End With
- TextBox1.SetFocus '对文字框设置焦点,类似于单击文字框
- Me.Caption = "查询蔬菜信息"
- ComboBox1.List = Array("全部", "蔬菜类", "肉食类", "蛋奶类", "粮类", "油类", "调味品类") '为复合框指定列表内容
- ComboBox1.Value = "蔬菜类" '为复合框指定显示内容
- 'ComboBox1.ListIndex = 0 ' 与 ComboBox1.Value= "蔬菜类 只能保留一个
- End Sub
复制代码
|
|