Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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_Excel - Fatal编程技术网

Vba 每隔一行删除一行

Vba 每隔一行删除一行,vba,excel,Vba,Excel,我想编写一个循环,删除工作表中的整行以清理文件。如果我有第1到10行,我想删除第1、3、5、7、9行 Sub deleteeveryotherrow() For x = 1 To 10 Rows("x:x").Select Selection.Delete Shift:=xlUp x = x + 2 Next x End Sub “x:x”只是一个文本字符串,因此无法按预期工作 使用行(x&“:”&x)。选择 您还应该考虑

我想编写一个循环,删除工作表中的整行以清理文件。如果我有第1到10行,我想删除第1、3、5、7、9行

Sub deleteeveryotherrow()
 For x = 1 To 10

     Rows("x:x").Select
        Selection.Delete Shift:=xlUp
        x = x + 2
        Next x

    End Sub
“x:x”
只是一个文本字符串,因此无法按预期工作

使用
行(x&“:”&x)。选择

您还应该考虑将循环从10到1运行:

对于x=9到1步骤-2

否则你会把索引搞得一团糟。然后您就可以删除该行
x=x+2

Sub deleteeveryotherrow()

For x = 1 To 100 Step 1

 Rows(x & ":" & x).Select
    Selection.Delete Shift:=xlUp

    Next x

End Sub

这很好地工作了

也许
对于x=9到1的步骤-2
…?哎呀。我们将联合出版!