- Sub yyy()
- Dim dx, dy, arr, i&, j&, k&, m&, n&, x&, y&, s2$, s3$, sz&, x1, y1
- Set dx = CreateObject("Scripting.Dictionary")
- Set dy = CreateObject("Scripting.Dictionary")
- arr = Range("a2", Cells(Rows.Count, 4).End(3)).Value
- x1 = Application.Min(Application.Index(arr, 0, 1))
- y1 = Application.Max(Application.Index(arr, 0, 1))
- x = Application.InputBox(Prompt:="输入开始日期", Default:=x1, Type:=1)
- y = Application.InputBox(Prompt:="输入结束日期", Default:=y1, Type:=1)
- If x > y Then MsgBox "开始日期比结束日期大,你玩我啊?", 0, "提示"
- ReDim brr(1 To UBound(arr) + 1, 1 To UBound(arr) + 2)
- brr(1, 1) = "开始-结束": brr(1, 2) = "姓名": brr(1, 3) = "销售额合计"
- brr(2, 1) = x: brr(3, 1) = y
- m = 1: n = 3
- For i = 1 To UBound(arr)
- If arr(i, 1) >= x And arr(i, 1) <= y Then
- s2 = arr(i, 2): s3 = arr(i, 3)
- If Not dy.exists(s2) Then
- m = m + 1
- dy(s2) = m
- brr(m, 2) = s2
- brr(m, 3) = arr(i, 4)
- Else
- brr(dy(s2), 3) = brr(dy(s2), 3) + arr(i, 4)
- End If
- If Not dx.exists(s3) Then
- n = n + 1
- dx(s3) = n
- brr(1, n) = s3
- End If
- brr(dy(s2), dx(s3)) = brr(dy(s2), dx(s3)) + arr(i, 4)
- sz = sz + arr(i, 4)
- End If
- Next
- brr(m + 1, 2) = "合计": brr(m + 1, 3) = sz
- With [G1]
- .CurrentRegion.Borders.LineStyle = 0
- .CurrentRegion.ClearContents
- .Resize(m + 1, n) = brr
- .Resize(m + 1, n).Borders.LineStyle = 1
- End With
- End Sub
复制代码 |