不在VBA中运行的外循环

我在脚本写作方面没有什么经验,我正尝试使用VBA在Excel中重新排列一大组数据。 脚本只通过内部循环,不运行外部循环。 任何指针为什么?

谢谢!

Row = 6 Column = 5 Destinationrow = 6 Destinationcolumn = 19 Do While Column <= 16 And Destinationcolumn <= 30 Do While Row <= 561 And Destinationrow <= 92 ActiveSheet.Cells(Row, Column).Select Selection.Copy ActiveSheet.Cells(Destinationrow, Destinationcolumn).Select ActiveSheet.Paste Row = Row + 9 Destinationrow = Destinationrow + 1 Loop Column = Column + 4 Destinationcolumn = Destinationcolumn + 1 Loop 

它看起来很好,除了你不重置你的行在内部循环的末尾。 也许它应该是:

 Column = 5 Destinationcolumn = 19 Do While Column <= 16 And Destinationcolumn <= 30 Row = 6 Destinationrow = 6 Do While Row <= 561 And Destinationrow <= 92 ActiveSheet.Cells(Row, Column).Select Selection.Copy ActiveSheet.Cells(Destinationrow, Destinationcolumn).Select ActiveSheet.Paste Row = Row + 9 Destinationrow = Destinationrow + 1 Loop Column = Column + 4 Destinationcolumn = Destinationcolumn + 1 Loop 

您必须在第一个循环内初始化行循环variables:

 Column = 5 Destinationcolumn = 19 Do While Column <= 16 And Destinationcolumn <= 30 Row = 6 Destinationrow = 6 Do While Row <= 561 And Destinationrow <= 92 ActiveSheet.Cells(Row, Column).Select Selection.Copy ActiveSheet.Cells(Destinationrow, Destinationcolumn).Select ActiveSheet.Paste Row = Row + 9 Destinationrow = Destinationrow + 1 Loop Column = Column + 4 Destinationcolumn = Destinationcolumn + 1 Loop 

你也可以用下面的代码来replace4个复制粘贴行:

 ActiveSheet.Cells(Destinationrow, Destinationcolumn) = ActiveSheet.Cells(Row, Column).Value