[英]VBA cut-paste range of data
I'm attempting to make a large amount of Genetic data, a little more legible in Excel using VBA.我正在尝试使用 VBA 在 Excel 中制作大量遗传数据,使其更加清晰。 I am trying to cut and paste every 7 cells that have data, after the 15th column, and drop them down under columns 8-15.
我试图在第 15 列之后剪切和粘贴每 7 个有数据的单元格,并将它们放到第 8-15 列下。 The example of what I need is in the picture included.
我需要的例子包括在图片中。 DATA EXAMPLE (RAW vs What i need it to look like) As you can see by the code, the real data is a little bigger.
数据示例(原始数据与我需要的样子) 正如您在代码中看到的,真实数据要大一些。 (At 680 rows and over 100 columns.)
(680 行和 100 多列。)
When I try running the code, it is failing when it goes to paste the range of data into the new line.当我尝试运行代码时,将数据范围粘贴到新行时失败。 (error 1004)
(错误 1004)
The code I have is:我的代码是:
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
Range.Cut allows you to specify the paste range after it. Range.Cut 允许您在其后指定粘贴范围。 Try something like:
尝试类似:
Range("A1:A3").Cut Range("B10")
Where you substitute my range values for the ones you want.您可以将我的范围值替换为您想要的范围值。
Your cell referrence is "H:N" & CurrentInsertRow
, or H:N2 for example, this is incomplete.例如,您的单元格引用是
"H:N" & CurrentInsertRow
或 H:N2,这是不完整的。 Try:尝试:
Range("H" & CurrentInsertRow & ":N" & CurrentInsertRow).Paste
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.