发布于 2022-04-29 12:31:34


其中一种方法是使用重复循环来执行数据的转换。
Public Sub transpose()
Dim lastRow As Integer
Dim startRow As Integer
Dim lastCol As Integer
Dim resultRow As Integer
resultRow = 2
lastRow = Planilha1.Range("A1000").End(xlUp).Row
lastCol = Planilha1.Range("A1").End(xlToRight).Column
startRow = 1
For iRow = startRow To lastRow
For iCol = 2 To lastCol
'col 7 and 8 = key and value
Planilha1.Cells(resultRow, 7) = Planilha1.Cells(iRow, 1)
Planilha1.Cells(resultRow, 8) = Planilha1.Cells(iRow, iCol)
resultRow = resultRow + 1
Next
Next
End Subhttps://stackoverflow.com/questions/72057723
复制相似问题