VBA将多列数据转置为行数据脚本
时间: 2024-03-12 17:49:17 浏览: 134
可以使用下面的VBA脚本将多列数据转置为行数据:
```VBA
Sub TransposeData()
Dim inputRange As Range
Dim outputRange As Range
Dim i As Integer
Dim j As Integer
Dim rowCount As Integer
Dim colCount As Integer
Set inputRange = Application.InputBox("Select the range of data to transpose", Type:=8)
rowCount = inputRange.Rows.Count
colCount = inputRange.Columns.Count
Set outputRange = Application.InputBox("Select the cell where the transposed data should be placed", Type:=8)
For i = 1 To rowCount
For j = 1 To colCount
outputRange.Offset(j - 1, i - 1).Value = inputRange.Cells(i, j).Value
Next j
Next i
End Sub
```
运行此宏后,它将提示您选择要转置的数据范围和输出范围。然后将使用嵌套的循环将数据从列转置为行,并将其放置在指定的输出范围中。
阅读全文