|
- Sub Test()
- Dim arr As Variant, brr As Variant, crr As Variant
- Dim lngRowID As Long, lngVal As Long
- Dim lngRows As Long, lngRow As Long, lngCol As Long
-
- lngRowID = 3 '起始行
- lngRows = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
- '数据区
- arr = Sheet1.Range("A" & lngRowID & ":I" & lngRows)
- '结果区
- Sheet1.Range("J" & lngRowID & ":AK" & lngRows) = ""
- brr = Sheet1.Range("J" & lngRowID & ":AK" & lngRows)
-
- For lngRow = 1 To UBound(arr)
- For lngCol = 1 To UBound(arr, 2)
- lngVal = arr(lngRow, lngCol)
- brr(lngRow, lngVal) = brr(lngRow, lngVal) + 1
- Next
- Next
-
- Sheet1.Range("J" & lngRowID & ":AK" & lngRows) = brr
-
- '总汇总区
- Sheet1.Range("J" & lngRows + 2 & ":AK" & lngRows + 2) = ""
- crr = Sheet1.Range("J" & lngRows + 2 & ":AK" & lngRows + 2)
-
- For lngCol = 1 To UBound(brr, 2)
- crr(1, lngCol) = Application.WorksheetFunction.Sum(Application.WorksheetFunction.Index(brr, 0, lngCol))
- Next
- Sheet1.Range("J" & lngRows + 2 & ":AK" & lngRows + 2) = crr
-
- '后10汇总区
- Sheet1.Range("J" & lngRows + 4 & ":AK" & lngRows + 4) = ""
- crr = Sheet1.Range("J" & lngRows + 2 & ":AK" & lngRows + 2)
-
- lngRowID = lngRows - 9
- brr = Sheet1.Range("J" & lngRowID & ":AK" & lngRows)
- For lngCol = 1 To UBound(brr, 2)
- crr(1, lngCol) = Application.WorksheetFunction.Sum(Application.WorksheetFunction.Index(brr, 0, lngCol))
- Next
- Sheet1.Range("J" & lngRows + 4 & ":AK" & lngRows + 4) = crr
-
- End Sub
复制代码 |
|