|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
转置-7 要求: 二维数据表 按项目名称展开,第1列为项目名称,第2-4列共3列为数据内容。
即,列数据按照最大3列进行折叠式展开。- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Count > 1 Then Exit Sub
- If Target.Column = 1 And Target.Row > 14 And Target = "" Then
- arr = Sheets(1).[a1].CurrentRegion
- m = UBound(arr)
- ReDim brr(1 To m, m)
- For i = 1 To m
- For j = 1 To m
- 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)
- GoTo Nxt
- End If
- Next
- End If
- Next
- Nxt:
- Next
- ReDim brr2(1 To m, -1 To 2)
- K = 0
- For i = 1 To l
- brr2(K + 1, -1) = brr(i, 0)
- For j = 0 To n - 1
- If brr(i, j + 1) = "" Then 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
复制代码 |
|