求vba用窗体列表框查询工作表内容代码
发布网友
发布时间:2022-04-30 00:07
我来回答
共1个回答
热心网友
时间:2022-06-26 19:59
Private Sub CommandButton1_Click()
Dim arr, i&, t1, t2, r, c, n, m&
r = ActiveSheet.UsedRange.Rows.Count
c = ActiveSheet.UsedRange.Columns.Count
arr = Range([a1], Cells(r, c))
t1 = TextBox1.Value
t2 = TextBox2.Value
n = Application.CountIfs([c:c], ">=" & t1, [c:c], "<=" & t2)
ReDim brr(1 To n + 1, 1 To c)
For i = 1 To c
brr(1, i) = arr(1, i)
Next
For i = 2 To UBound(arr)
If arr(i, 3) >= DateValue(t1) And arr(i, 3) <= DateValue(t2) Then
For j = 1 To c
brr(m + 2, j) = arr(i, j)
Next
m = m + 1
End If
Next
ListBox1.ColumnCount = c
ListBox1.List = brr
End Sub