我正在将Tabular数据上传到我的SQL数据库中。
以下是数据的原始外观。
我想在列中取每个温度(Y轴),然后在下一列中取每个重力(X轴),然后是交叉值。
喜欢这个:
答案 0 :(得分:2)
我得到了ExcelForum的帮助。这是宏代码,它解决了我的问题。
Option Explicit
Sub transpose_data()
Dim lrow As Long, lcol As Long, a As Long, i As Long, j As Long
Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = "Output"
a = 1
With Worksheets("Original")
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
lcol = .Range("IV1").End(xlToLeft).Column
For i = 2 To lrow
For j = 2 To lcol
Worksheets("Output").Cells(a, 1).Value = .Cells(i, 1).Value
Worksheets("Output").Cells(a, 2).Value = .Cells(1, j).Value
Worksheets("Output").Cells(a, 3).Value = .Cells(i, j).Value
a = a + 1
Next j
Next i
End With
Worksheets("Output").Columns("A:C").NumberFormat = "0.00"
End Sub
确保将工作表名称更改为“原始”,以使此代码正常工作。