为什么我的宏不会删除所有行(VBA) [英] Why my macro doesn't delete all the rows (VBA)

查看:107
本文介绍了为什么我的宏不会删除所有行(VBA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个宏,它应该删除所有没有背景设置的单元格,但是当我执行宏,如果两个或更多个连续的单元格没有背景,它只会删除其中的一个,这里是代码:

  Sub Macro1()
Dim a As Range

设置a = Hoja1 .Range(A1:A12)
对于每个单元格在
中如果cell.Interior.ColorIndex = xlNone然后
cell.EntireRow.Delete
End If
Next
End Sub


解决方案

 code> Sub Macro1()
Dim a As Range,x As Long

设置a = Hoja1.Range(A1:A12)

对于x = a.cells.count到1 Step -1
with a.cells(x)
if .Interior.ColorIndex = xlNone Then .EntireRow.Delete
End With
Next x
End Sub


i have this macro it is supposed to delete all the cells that doesnt have a background set to them, but when I execute the macro if two or more contiguous cells doesnt have a background it only deletes one of them, here is the code:

Sub Macro1()
        Dim a As Range

        Set a = Hoja1.Range("A1:A12")
        For Each cell In a
            If cell.Interior.ColorIndex = xlNone Then
                cell.EntireRow.Delete
            End If
        Next
End Sub

解决方案

Sub Macro1()
    Dim a As Range, x As Long

    Set a = Hoja1.Range("A1:A12")

    For x = a.cells.count to 1 Step -1
        with a.cells(x)
            if .Interior.ColorIndex = xlNone Then .EntireRow.Delete
        End With
    Next x
End Sub

这篇关于为什么我的宏不会删除所有行(VBA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆