求excel应用
姓名班级数学语文
张三29597
李四26677
王五19995
转换后变成
姓名班级课程分数
张三2数学95
张三2语文97
李四2数学66
李四2语文77
王五1数学99
王五1语文95
备注:
姓名很多,不固定
课程很多,不固定。
多谢
[解决办法]
Sheets(1)为原数据表格
Sheets(2)为转换出的新表格
Sub Score()
Dim TotalRow As Long, TotalCol As Integer
Dim CurRow1 As Long, CurRow2 As Long, CurCol1 As Integer
Dim S1 As Worksheet, S2 As Worksheet
TotalRow = [A65536].End(xlUp).Row
TotalCol = [IV1].End(xlToLeft).Column
Set S1 = Sheets(1)
Set S2 = Sheets(2)
S2.Cells(1, 1) = "姓名"
S2.Cells(1, 2) = "班级"
S2.Cells(1, 3) = "课程"
S2.Cells(1, 4) = "分数"
CurRow2 = 2
For CurRow1 = 2 To TotalRow
For CurCol1 = 3 To TotalCol
S2.Cells(CurRow2, 1) = S1.Cells(CurRow1, 1)
S2.Cells(CurRow2, 2) = S1.Cells(CurRow1, 2)
S2.Cells(CurRow2, 3) = S1.Cells(1, CurCol1)
S2.Cells(CurRow2, 4) = S1.Cells(CurRow1, CurCol1)
CurRow2 = CurRow2 + 1
Next CurCol1
Next CurRow1
End Sub