|
- Sub test11() '
- Dim results(), data, dict As Object, strKey As String, i As Long, j As Long
- Dim rowSize As Long, colSize As Long, posRow As Long, posCol As Long, yyyy As Long
-
- yyyy = Val(Application.InputBox("年?", "T", Year(Date)))
- If yyyy = 0 Then Exit Sub
-
- Application.ScreenUpdating = False
- rowSize = 1
- colSize = 1
- Set dict = CreateObject("Scripting.Dictionary")
-
- data = Worksheets("客户").Range("A1").CurrentRegion.Value
- ReDim results(1 To UBound(data), 1 To 14)
- results(rowSize, colSize) = data(1, 4)
- For j = 1 To 12
- colSize = colSize + 1
- results(rowSize, colSize) = j & "月"
- Next
- For i = 2 To UBound(data)
- If Year(data(i, 2)) = yyyy Then
- strKey = Trim(data(i, 4))
- If Not dict.Exists(strKey) Then
- rowSize = rowSize + 1
- results(rowSize, 1) = strKey
- dict.Add strKey, rowSize
- End If
- posRow = dict(strKey)
- posCol = Month(data(i, 2)) + 1
- results(posRow, posCol) = results(posRow, posCol) + Val(data(i, 11))
- End If
- Next
- rowSize = rowSize + 1
- colSize = colSize + 1
- results(rowSize, 1) = "合计"
- results(1, colSize) = "合计"
- For j = 2 To colSize - 1
- For i = 2 To rowSize - 1
- results(rowSize, j) = results(rowSize, j) + results(i, j)
- results(i, colSize) = results(i, colSize) + results(i, j)
- Next
- results(i, colSize) = results(i, colSize) + results(i, j)
- Next
- With Worksheets("统计表").Range("A2")
- .CurrentRegion.Offset(1).Clear
- With .Resize(rowSize, colSize)
- .HorizontalAlignment = xlCenter
- .Borders.LineStyle = xlContinuous
- .Rows(1).Font.Bold = True
- .Value = results
- .Resize(rowSize - 1).Sort .Item(1), xlAscending, , , , , , xlYes
- End With
- End With
-
- Set dict = Nothing
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|