|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub CX_查询系统查询按钮()
Application.ScreenUpdating = False
Dim br()
Dim dRow As Long
Dim kH As String
Dim mC As String
Range("D4:P" & Rows.Count).ClearContents
Range("D4:P" & Rows.Count).Borders.LineStyle = xlNone
If Trim(CStr(Range("B3").Value)) = "" Then
ks = CDate("1900-01-01")
Else
If IsDate(Trim(CStr(Range("B3").Value))) Then
ks = CDate(Trim(CStr(Range("B3").Value)))
Else
MsgBox "输入的起始日期不正确,请重新核对!", 48, "系统提示"
Range("B3").Select
Exit Sub
End If
End If
If Trim(CStr(Range("B4").Value)) = "" Then
js = CDate("2100-12-31")
Else
If IsDate(Trim(CStr(Range("B4").Value))) Then
js = CDate(Trim(CStr(Range("B4").Value)))
Else
MsgBox "输入的结束日期不正确,请重新核对!", 48, "系统提示"
Range("B4").Select
Exit Sub
End If
End If
If js < ks Then
MsgBox "输入的结束日期不能小于开始日期,请重新核对!", 48, "系统提示"
Range("B3").Select
Exit Sub
End If
kH = Trim(CStr(Range("B6").Value))
mC = UCase(Trim(CStr(Range("B8").Value)))
rr = Array(ks, 2, js, 2, kH, 1, mC, 5)
Dim mr()
ReDim mr(1 To 5, 1 To 3)
For i = 0 To UBound(rr) Step 2
If Trim(rr(i)) <> "" Then
n = n + 1
mr(n, 1) = rr(i)
mr(n, 2) = rr(i + 1)
If rr(i) = ks Then
mr(n, 3) = "开始"
ElseIf rr(i) = js Then
mr(n, 3) = "结束"
Else
mr(n, 3) = ""
End If
End If
Next i
If n = "" Then MsgBox "请至少输入一个查询条件!": End
With Sheet3
r = .Cells(Rows.Count, "A").End(xlUp).Row
If r < 2 Then MsgBox "订单登记表为空": End
ar = .Range("a1:m" & r)
End With
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
sl = 0
For s = 1 To n
mC = mr(s, 1)
lh = mr(s, 2)
BJ = mr(s, 3)
If BJ = "" Then
If Trim(ar(i, lh)) = Trim(mC) Then
sl = sl + 1
End If
ElseIf BJ <> "" Then
If BJ = "开始" Then
If ar(i, lh) >= mC Then
sl = sl + 1
End If
ElseIf BJ = "结束" Then
If ar(i, lh) <= mC Then
sl = sl + 1
End If
End If
End If
Next s
If sl = n Then
m = m + 1
hj = hj + ar(i, 9)
je = je + ar(i, 10)
For j = 1 To 13
br(m, j) = ar(i, j)
Next j
End If
Next i
If m = "" Then MsgBox "没有符合条件的数据!": End
[d4].Resize(m, UBound(br, 2)) = br
[d4].Resize(m, UBound(br, 2)).Borders.LineStyle = 1
[e2] = m
[l2] = hj
[m2] = je
Application.ScreenUpdating = True
MsgBox "OK!"
End Sub
|
|