Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用VBA移动行,但出现错误,无法';我不知道如何修理它_Vba_Cell_Move - Fatal编程技术网

尝试使用VBA移动行,但出现错误,无法';我不知道如何修理它

尝试使用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

所以我有一个代码,它通过一个电子表格(大约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).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”: 此选择无效。 有几个可能的原因:

  • 复制和粘贴区域不能重叠,除非它们大小相同
  • 如果使用“从选择创建”命令,则包含建议名称的行或列将不包括在。。。(它被错误框的底部切断)

关于错误消息的快速指针:您可以在显示错误消息时按Ctrl+C复制整个错误消息,然后将其粘贴到您选择的编辑器中进行读取/保存。这应该可以让您阅读整个消息,即使错误框格式似乎将其截断。您的代码对我来说运行良好。我想知道是否有特定的行/位置导致了问题。这是否适用于其他数据?您是否可以编辑您的问题以包含您正在使用的数据快照?在循环进行的过程中,您是否已完成循环,以查看是否是特定行触发了循环?