|
楼主 |
发表于 2024-9-21 09:19
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Option Explicit
- Private Sub ComboBox1_Change()
- End Sub
- Private Sub ComboBox2_Change()
- End Sub
- '查询按钮
- Private Sub CommandButton1_Click()
- If ComboBox1 = "" Then MsgBox " 报错:未选择部门", 48, " ": Exit Sub
- If DateValue(TextBox1) > DateValue(TextBox2) Then MsgBox " 报错:开始日期>结束日期", 48, " ": Exit Sub
- Dim i, arr, d
-
- With Sheet9
- .Unprotect
- .Range("c7:p" & .Rows.Count).ClearContents '清空查询表
-
- With Sheet2 '全部明细数组
- arr = .Range("c6:p" & .Range("c" & .Rows.Count).End(3).Row)
- End With
-
- d = 7
- For i = 2 To UBound(arr)
- If arr(i, 1) >= DateValue(TextBox1) And arr(i, 1) <= DateValue(TextBox2) And arr(i, 10) = ComboBox1 Then
- .Cells(d, 3).Resize(1, UBound(arr, 2)) = Application.WorksheetFunction.Index(arr, i)
- d = d + 1
- End If
- Next
-
- .Range("J4") = "查询条件:" & ComboBox1 & "," & TextBox1 & "至" & TextBox2 & ComboBox2
-
- .Protect
- End With
-
- Unload Me
- End Sub
- Private Sub Label1_Click()
- End Sub
- Private Sub Label2_Click()
- End Sub
- '开始日期TextBox1_MouseDown
- Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
- QYrl.Show
- If IsDate(QYrl.dts) Then TextBox1 = Format(QYrl.dts, "yyyy-mm-dd")
- Unload QYrl
- End Sub
- '结束日期TextBox2_MouseDown
- Private Sub TextBox2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
- QYrl.Show
- If IsDate(QYrl.dts) Then TextBox2 = Format(QYrl.dts, "yyyy-mm-dd")
- Unload QYrl
- End Sub
- Private Sub UserForm_Initialize()
- TextBox1 = Format(Date, "yyyy-mm-dd")
- TextBox2 = Format(Date, "yyyy-mm-dd")
- '经办部门list
- Dim i, arr
- With Sheet3
- arr = .Range("c5", .Cells(6, .Cells(5, .Columns.Count).End(1).Column))
- For i = 1 To UBound(arr, 2)
- ComboBox1.AddItem arr(1, i)
- Next
- End With
- End Sub
- Private Sub ComboBox1_Change()
- On Error Resume Next
- ComboBox2.Clear
- Dim n, m, i, arr
- With Sheet3
- n = Application.WorksheetFunction.Match(ComboBox1, .Rows("5:5"), 0)
- m = Application.WorksheetFunction.CountA(.Columns(n))
- arr = .Cells(5, n).Resize(m, 2)
- For i = 2 To UBound(arr)
- ComboBox2.AddItem arr(i, 1)
- Next
- End With
-
- End Sub
复制代码 |
|