|
转置-9 要求: 二维数据表 按照相同项目进行最大3列的折叠式展开,
其中第1列第1行为项目名称,第1列第2行要求统计数据个数,即: 总共(n人)- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then Exit Sub
- If Target.Column = 1 And Target.Row > 16 And Target = "" Then
- arr = Sheets(1).[a1].CurrentRegion
- m = UBound(arr)
- ReDim brr(1 To m * 2, m)
- For i = 1 To m
- For j = 1 To m * 2 Step 2
- If arr(i, 1) = brr(j, 0) Or brr(j, 0) = "" Then
- If j > l Then l = j
- For K = 1 To m
- If brr(j, K) = "" Then
- If K > n Then n = K
- brr(j, 0) = arr(i, 1)
- brr(j, K) = arr(i, 2)
- brr(j + 1, 0) = brr(j + 1, 0) + 1
- GoTo Nxt
- End If
- Next
- End If
- Next
- Nxt:
- Next
-
- For j = 1 To l Step 2
- brr(j + 1, 0) = ChrW(24635) & ChrW(20849) & "(" & brr(j + 1, 0) & ChrW(20154) & ")"
- Next
-
- ReDim brr2(1 To m * 2, -1 To 2)
- K = 0
- For i = 1 To l Step 2
- brr2(K + 1, -1) = brr(i, 0)
- brr2(K + 2, -1) = brr(i + 1, 0)
- For j = 0 To n - 1
- If brr(i, j + 1) = "" Then If j < 4 Then K = K + 1: Exit For
- If j Mod 3 = 0 Then K = K + 1
- brr2(K, j Mod 3) = brr(i, j + 1)
- Next
- Next
- Target.Resize(K, 4) = brr2
- End If
- End Sub
复制代码 |
|