VBA剪切粘贴数据范围
我正在尝试使用VBA制作大量的基因数据,在Excel中更加清晰。我试图在第15列之后剪切并粘贴每7个有数据的单元格,并将它们放在第8-15列下。 我需要的例子在图片中。(原始数据与我需要它的样子)正如您从代码中看到的,真实数据稍微大一点。(680行和超过100列。) 当我尝试运行代码时,将数据范围粘贴到新行时失败。(错误1004) 我的密码是:VBA剪切粘贴数据范围,vba,excel,Vba,Excel,我正在尝试使用VBA制作大量的基因数据,在Excel中更加清晰。我试图在第15列之后剪切并粘贴每7个有数据的单元格,并将它们放在第8-15列下。 我需要的例子在图片中。(原始数据与我需要它的样子)正如您从代码中看到的,真实数据稍微大一点。(680行和超过100列。) 当我尝试运行代码时,将数据范围粘贴到新行时失败。(错误1004) 我的密码是: Sub ShiftRows() Dim codingCol, startCol As Integer Dim LastRow As
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
Sub-ShiftRows()
Dim codingCol,startCol为整数
将最后一行设置为整数
将CurrentRow设置为整数
Dim LastCol,BeginCol为整数
将CurrentInsertRow设置为整数
最后一行=2
对于CurrentRow=680到LastRow步骤-1
LastCol=15
执行While单元格(CurrentRow,LastCol)”“
LastCol=LastCol+1
环
CurrentInsertRow=CurrentRow
对于BeginCol=0到((LastCol-15)/7)-1
CurrentInsertRow=CurrentInsertRow+1
行(CurrentRow).偏移量(1).插入移位:=xlShiftDown
范围(单元格(当前行,15+(BeginCol*7))。地址和“:”&单元格(当前行,15+(BeginCol*7)+6)。地址)。剪切
范围(“H:N”和CurrentInsertRow)。粘贴
下贝金科
下一行
端接头
您的单元格引用是“H:N”&CurrentInsertRow
,或者是H:N2,例如,这是不完整的。尝试:
Range("H" & CurrentInsertRow & ":N" & CurrentInsertRow).Paste
您的单元格引用是
“H:N”&CurrentInsertRow
,例如,这是不完整的。尝试:
Range("H" & CurrentInsertRow & ":N" & CurrentInsertRow).Paste
剪切允许您在其后面指定粘贴范围。尝试以下方法:
Range("A1:A3").Cut Range("B10")
将我的范围值替换为所需的范围值 Range.Cut允许您在其后面指定粘贴范围。尝试以下方法:
Range("A1:A3").Cut Range("B10")
将我的范围值替换为所需的范围值 首先,谢谢你的回答!但返回错误:对象不支持此属性或方法..:/1首先,感谢您的回答!但是,返回了错误:对象不支持此属性或方法..:/n您是否发现了这一点?我下面建议的答案有用吗?你有没有想过?我下面建议的答案有用吗?