尝试使用VBA移动行,但出现错误,无法';我不知道如何修理它
所以我有一个代码,它通过一个电子表格(大约150000行)并突出显示特定的红色。现在,我正在尝试移动这些选定的行,下面是我的代码:尝试使用VBA移动行,但出现错误,无法';我不知道如何修理它,vba,cell,move,Vba,Cell,Move,所以我有一个代码,它通过一个电子表格(大约150000行)并突出显示特定的红色。现在,我正在尝试移动这些选定的行,下面是我的代码: Dim x As Long, iInsertedRows As Integer x = Range("A1").End(xlDown).Row For x = x To 1 Step -1 If Cells(x, 1).Interior.ColorIndex = 3 Then '3 is standard red color Rows(x
Dim x As Long, iInsertedRows As Integer
x = Range("A1").End(xlDown).Row
For x = x To 1 Step -1
If Cells(x, 1).Interior.ColorIndex = 3 Then '3 is standard red color
Rows(x).Cut
'''The next row is where it breaks'''
Rows("1:1").Insert shift:=xlDown 'paste the cut row back as row 1
x = x + 1 'we've just moved everything down a row
iInsertedRows = iInsertedRows + 1
If iInsertedRows = x Then Exit For 'we don't need to sort the ones we put there
End If
Next
(来源:)
问题是,我收到一个错误,内容如下:
运行时错误“1004”:
此选择无效。
有几个可能的原因:
- 复制和粘贴区域不能重叠,除非它们大小相同
- 如果使用“从选择创建”命令,则包含建议名称的行或列将不包括在。。。(它被错误框的底部切断)