|
- Private Sub cmd时间段查询_Click()
- Dim time1 As String, time2 As String ' Variant
- Dim arr, a(), i&, j%, n&
- arr = Sheets("数据源").Range("A1").CurrentRegion
- time1 = InputBox("请输入期刊开始日期(例:xxxxxxxx)", "期刊日期查询")
- time2 = InputBox("请输入期刊结束日期(例:xxxxxxxx)", "期刊日期查询")
- For i = 2 To UBound(arr)
- If CStr(arr(i, 5)) >= time1 And CStr(arr(i, 5)) <= time2 Then
- n = n + 1: ReDim Preserve a(1 To 5, 1 To n)
- For j = 1 To 5
- a(j, n) = arr(i, j)
- Next
- End If
- Next
- Sheets("结果").Select
- Range("a2:h100").Clear
- If n > 0 Then
- MsgBox "共有 " & n & "条 记录"
- Range("a2").Resize(n, 5) = WorksheetFunction.Transpose(a)
- Else
- MsgBox "未找到数据。"
- End If
- ListBox1.ColumnCount = 8
- ListBox1.ColumnWidths = "120,40,40"
- ListBox1.RowSource = Range("a1:E" & n + 1).Address
- End Sub
复制代码 |
|