当前位置: 代码迷 >> VBA >> 怎么判断Excel中的一整行是否为空,并删除
  详细解决方案

怎么判断Excel中的一整行是否为空,并删除

热度:9574   发布时间:2013-02-26 00:00:00.0
如何判断Excel中的一整行是否为空,并删除
如何用VBA来判断Excel中的一整行是否为空,为空的话删除整行。

------解决方案--------------------------------------------------------
做了个简单的,其中单元格的判断可以替换为数组中循环更快些,不过我没写在里面,应该比较好修改,你看看是不是这样.
VB code
Sub ttt()    Dim Ro As Long    Application.ScreenUpdating = False    For Ro = 65536 To 1 Step -1        If IsEmpty(Cells(Ro, 1)) Then            If Cells(Ro, 1).End(xlToRight).Column = 256 Then                If IsEmpty(Cells(Ro, 1).End(xlToRight)) Then Rows(Ro).Delete            End If        End If    Next Ro    Application.ScreenUpdating = TrueEnd Sub
------解决方案--------------------------------------------------------
用countblank试试看
------解决方案--------------------------------------------------------
探讨
改了之后也没感觉快多少..
VB codeSub ttt()Dim RoAsLongDim arrCAAs VariantDim arrEndAs Variant
Application.ScreenUpdating=False
arrCA= Columns(1)
arrEnd= Columns(256)For Ro=65536To1 Step-1If arrCA(Ro,1)=""ThenIf Cells(Ro,1).End(xlToRight).Column=256ThenIf arrEnd(Ro,1)=""Then Rows(Ro).DeleteEndIfEndIfNext Ro
Application.ScreenUpdating=TrueEnd Sub
  相关解决方案