我在EXCEL里的VB编写了一个查询窗体,请问怎么写代码?
1个回答
展开全部
Option Explicit
Dim arr, brr, i As Long
Private Sub ComboBox1_Change()
Dim R As Long
ListBox1.Clear
R = WorksheetFunction.Match(ComboBox1.Text, brr, 0) + 2
For i = 2 To UBound(arr, 2) Step 2
With ListBox1
.AddItem arr(2, i)
.List(.ListCount - 1, 1) = arr(R, i)
.List(.ListCount - 1, 2) = arr(R, i + 1)
End With
Next
End Sub
Private Sub UserForm_Initialize()
arr = Range("A1").CurrentRegion
brr = Range("A3:A" & UBound(arr))
ComboBox1.List = brr
ComboBox1.ListIndex = 0
With ListBox1
.ColumnCount = 3
.ColumnWidths = "72;100;120"
End With
End Sub
对照修改单元格及数据即可。
Dim arr, brr, i As Long
Private Sub ComboBox1_Change()
Dim R As Long
ListBox1.Clear
R = WorksheetFunction.Match(ComboBox1.Text, brr, 0) + 2
For i = 2 To UBound(arr, 2) Step 2
With ListBox1
.AddItem arr(2, i)
.List(.ListCount - 1, 1) = arr(R, i)
.List(.ListCount - 1, 2) = arr(R, i + 1)
End With
Next
End Sub
Private Sub UserForm_Initialize()
arr = Range("A1").CurrentRegion
brr = Range("A3:A" & UBound(arr))
ComboBox1.List = brr
ComboBox1.ListIndex = 0
With ListBox1
.ColumnCount = 3
.ColumnWidths = "72;100;120"
End With
End Sub
对照修改单元格及数据即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询