|
- 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
-
- Application.ScreenUpdating = False
-
- Set dict = CreateObject("Scripting.Dictionary")
- data = Sheet1.Range("A1").CurrentRegion.Value
- ReDim results(1 To UBound(data), 1 To 14)
- rowSize = 1
- colSize = 1
- results(rowSize, colSize) = data(1, 2)
- For i = 2 To UBound(data)
- strKey = Trim(data(i, 2))
- If Not dict.Exists(strKey) Then
- rowSize = rowSize + 1
- results(rowSize, 1) = strKey
- dict.Add strKey, rowSize
- End If
- posRow = dict(strKey)
- strKey = Format(CDate(data(i, 1)), "M月") '开什么玩笑,2018-02-29 存在吗?在这个地方搞晕了。
- If strKey = "" Then strKey = "(空白)"
- If Not dict.Exists(strKey) Then
- colSize = colSize + 1
- results(1, colSize) = strKey
- dict.Add strKey, colSize
- End If
- posCol = dict(strKey)
- results(posRow, posCol) = results(posRow, posCol) + Val(data(i, 8))
- 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 Sheet1.Range("N1")
- .CurrentRegion.Clear
- With .Resize(rowSize, colSize)
- .HorizontalAlignment = xlCenter
- .Borders.LineStyle = xlContinuous
- .Rows(1).Font.Bold = True
- .Value = results
- End With
- End With
- Set dict = Nothing
-
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|