|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub qs()
- Dim arr, i, dic
- Set dic = CreateObject("scripting.dictionary")
- With Sheet2
- arr = .UsedRange.Value
- End With
- ReDim brr(1 To UBound(arr), 1 To 4)
- With Sheet3
- dt1 = CDate(.[a2].Value): dt2 = CDate(.[c2].Value)
- For i = 4 To UBound(arr)
- dt = CDate(arr(i, 1))
- If dt >= dt1 And dt <= dt2 Then
- s = arr(i, 3)
- If Not dic.exists(s) Then
- m = m + 1
- dic(s) = m
- brr(m, 1) = s: brr(m, 2) = arr(i, 5)
- brr(m, 3) = arr(i, 6): brr(m, 4) = brr(m, 2) - brr(m, 3)
- Else
- rw = dic(s)
- brr(rw, 2) = brr(rw, 2) + arr(i, 5): brr(rw, 3) = brr(rw, 3) + arr(i, 6):
- brr(rw, 4) = brr(rw, 2) - brr(rw, 3)
- End If
-
- End If
- Next
- .[b3].Value = Application.Sum(Application.Index(brr, 0, 2))
- .[c3].Value = Application.Sum(Application.Index(brr, 0, 3))
- .[d3].Value = Application.Sum(Application.Index(brr, 0, 4))
- .[a5].Resize(m, 4) = brr
- End With
- Set dic = Nothing
- Beep
- End Sub
复制代码 |
|