0
A
回答
0
請試試這個...
'************************************************************************
'The code will work like this
'1) UnPivot the data on Sheet1
'2) Insert a New Sheet called Tranposed if not available in the workbook
'3) Place the output i.e. UnPivoted data on the Transposed Sheet.
'************************************************************************
Sub UnPivotData()
Dim wsSource As Worksheet, wsDest As Worksheet
Dim x, y, i As Long, j As Long, n As Long
'Assuming your raw data is on a sheet called "Sheet1", change it if required
Set wsSource = Sheets("Sheet1")
x = wsSource.Cells(1).CurrentRegion.Value
ReDim y(1 To UBound(x, 1) * UBound(x, 2), 1 To 2)
For i = 2 To UBound(x, 1)
For j = 2 To UBound(x, 2)
If x(i, j) <> "" Then
n = n + 1
y(n, 1) = x(i, 1)
y(n, 2) = x(i, j)
End If
Next
Next
On Error Resume Next
Set wsDest = Sheets("Transposed")
wsDest.Cells.Clear
On Error GoTo 0
If wsDest Is Nothing Then
Sheets.Add(after:=wsSource).Name = "Transposed"
Set wsDest = ActiveSheet
End If
wsDest.Range("A1:B1").Value = Array("Number", "Deatils")
wsDest.Range("A2").Resize(UBound(y), 2).Value = y
wsDest.Range("A1").CurrentRegion.Borders.Color = vbBlack
MsgBox "Data Transposed Successfully.", vbInformation, "Done!"
End Sub
相關問題
- 1. VBA:簡單日期宏不起作用
- 2. 簡單的Excel宏
- 3. VBA - 簡化的複製和粘貼宏
- 4. VBA宏隱藏表
- 5. 簡單的VBA宏,允許用戶插入自定義編號
- 6. LLDB中的簡單宏?
- 7. excel上的簡單宏
- 8. SAS簡單的宏 - 錯誤
- 9. 簡單的NSLog宏觀
- 10. Excel VBA:啓用宏設置
- 11. VBA簡單代碼
- 12. VBA簡單解析
- 13. VBA宏的Excel
- 14. 如何編寫(簡單)宏?
- 15. 應堅持VBA/VBScript中的宏設置
- 16. 單擊所有按鈕的VBA宏
- 17. 單詞vba宏 - 動態引用表單元素
- 18. 一個簡單的C++ 11的宏
- 19. 簡單的Excel VBA宏:誤差範圍類的1004方法失敗
- 20. 繞過VBA中的表單並繼續執行宏
- 21. 如何在excel表單上顯示vba宏的狀態?
- 22. 基於映射表的VBA宏更新單元格
- 23. 呼叫VBA加載宏宏
- 24. VBA中的VLOOKUP宏
- 25. VBA宏刪除Word表中的空行
- 26. 如何在VBA Excel宏中設置單元測試?
- 27. 使用一個簡單的assert()宏
- 28. 簡單的斯卡拉宏觀
- 29. 簡單VBA代碼問題
- 30. 使用VBA宏
請提供你....嘗試過的代碼,以便我們可以幫助您更多.... –
查找到技術,「逆透視」。這可以在沒有VBA的情況下完成。 Power Query是一種選擇。支點表反轉樞軸是另一回事。使用你的谷歌技能。 – teylyn