|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 转置()
- Cells.Clear
- Cells.UnMerge
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Sheet5.Activate ''结果表
- Arr = Sheet1.[A1].CurrentRegion ''数据源
- For i = 2 To UBound(Arr)
- x = Arr(i, 2) '''
- y = Arr(i, 1) '''
- d1(y) = ""
- If d.exists(x) = False Then Set d(x) = CreateObject("Scripting.Dictionary")
- d(x)(y) = d(x)(y) & "," & Arr(i, 3) & "," & Arr(i, 4) & "," & Arr(i, 5) & "," & Arr(i, 6) & "," & Arr(i, 7)
- Next
- k = d.Keys
- t = d.items
- k1 = d1.Keys
- For r = 1 To d.Count
- Cells((r - 1) * 25 + 5, 1).Resize(12, 1) = k(r - 1) '''
- Next
- For c = 1 To d1.Count
- Cells(1, (c - 1) * 9 + 2).Resize(1, 9) = k1(c - 1) ''
- Next
- N = 5
- With Sheets("Sheet3") '''结果表
- Arr = .UsedRange
- For i = 5 To UBound(Arr) Step 25 '''///
- If d.exists(Arr(i, 1)) Then ''
- For j = 2 To UBound(Arr, 2) - 1 Step 9
- If d(Arr(i, 1)).exists(Arr(1, j)) Then ''''////
- SS = Split(Mid(d(Arr(i, 1))(Arr(1, j)), 2), ",") '''///
- For r = 0 To UBound(SS) / N
- For M = 1 To N
- If UBound(SS) = 0 Then
- Arr(i, j + M - 1) = "'" & Split(Mid(d(Arr(i, 1))(Arr(1, j)), 2), ",")(M - 1) '''///
- Else
- Arr(i + r, j + M - 1) = "'" & Split(Mid(d(Arr(i, 1))(Arr(1, j)), 2), ",")(r * N + M - 1) '''///
- End If
- Next
- Next
- End If
- Next j
- End If
- Next i
- .UsedRange = Arr
- End With
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For j = 2 To UBound(Arr, 2) Step 9
- Range(Cells(1, j), Cells(1, j + 8)).Merge
- Next
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- Cells.EntireColumn.AutoFit '
- Cells.HorizontalAlignment = xlCenter
- d.RemoveAll
- d1.RemoveAll
- Erase Arr '
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|