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