要将表1的数据转换为表三的数据。所编代码如下,可运行时总不能达到预期效果,请帮忙修正。图表见附件。
Dim j As Integer
Dim K As Integer
Dim L As Integer
Sub 转换数据()
Application.ScreenUpdating = False
'关闭执行程序时发生的屏幕更新,加快运行速度。
Sheets("Sheet1").Select
iCount = Sheets("Sheet1").[A1].CurrentRegion.Rows.Count
For j = 1 To iCount
Rows(j).Select
Sheets("Sheet3").Cells(1, 1) = Cells(j, 1)
Sheets("Sheet3").Cells(1, 2) = Cells(j, 2)
Sheets("Sheet3").Cells(1, 3) = Cells(j, 3)
Sheets("Sheet3").Cells(1, 4) = Cells(j, 4)
Sheets("Sheet3").Cells(1, 5) = Cells(j + 1, 1)
Sheets("Sheet3").Cells(1, 6) = Cells(j + 1, 2)
Sheets("Sheet3").Cells(1, 7) = Cells(j + 1, 3)
Sheets("Sheet3").Cells(1, 8) = Cells(j + 1, 4)
Sheets("Sheet3").Cells(1, 9) = Cells(j + 2, 1)
Sheets("Sheet3").Cells(1, 10) = Cells(j + 2, 2)
Sheets("Sheet3").Cells(1, 11) = Cells(j + 2, 3)
Sheets("Sheet3").Cells(1, 12) = Cells(j + 2, 4)
Sheets("Sheet3").Select
L = WorksheetFunction.Count(Range("A1:A1000")) '假设转换后数据行数为1000,该值可变化。
Range(Cells(1, 1), Cells(1, 12)).Copy
Cells(L + 1, 1).Select
ActiveSheet.Paste
Range("A1:L1").Select
Application.CutCopyMode = False
Selection.ClearContents
Sheets("Sheet1").Select
j = j + 3
Next j
Sheets("Sheet3").Select
Range("A1").Select
End Sub
CyE7Dqwf.rar
(7.15 KB, 下载次数: 17)
|