【发布时间】:2016-10-07 14:24:40
【问题描述】:
我正在尝试使用 VBA 在 Excel 中制作大量遗传数据,使其更清晰易读。我试图在第 15 列之后剪切和粘贴每 7 个有数据的单元格,并将它们放在第 8-15 列下。 我需要的示例在包含的图片中。 DATA EXAMPLE (RAW vs What I need it to look like) 正如您从代码中看到的那样,真实数据要大一些。 (680 行和 100 多列。)
当我尝试运行代码时,将数据范围粘贴到新行时失败。 (错误 1004)
我的代码是:
Sub ShiftRows()
Dim codingCol, startCol As Integer
Dim LastRow As Integer
Dim CurrentRow As Integer
Dim LastCol, BeginCol As Integer
Dim CurrentInsertRow As Integer
LastRow = 2
For CurrentRow = 680 To LastRow Step -1
LastCol = 15
Do While Cells(CurrentRow, LastCol) <> ""
LastCol = LastCol + 1
Loop
CurrentInsertRow = CurrentRow
For BeginCol = 0 To ((LastCol - 15) / 7) - 1
CurrentInsertRow = CurrentInsertRow + 1
Rows(CurrentRow).Offset(1).Insert shift:=xlShiftDown
Range(Cells(CurrentRow, 15 + (BeginCol * 7)).Address & ":" & Cells(CurrentRow, 15 + (BeginCol * 7) + 6).Address).Cut
Range("H:N" & CurrentInsertRow).Paste
Next BeginCol
Next CurrentRow
End Sub
【问题讨论】:
-
你有没有想过这个问题?我在下面建议的答案有帮助吗?