注册 登录
编程论坛 VB6论坛

在2016版excel运行清零太慢,请问如何编写

刘学斌 发布于 2021-04-07 11:47, 1593 次点击
Sub 删除行()
   
    r = 3
    Do While Cells(r, 3).Value <> ""
         
        If Cells(r, 12).Value <= 0 And Cells(r, 3).Value <> "" Then
           Rows(r).Delete
           r = r - 1
        End If
        r = r + 1
    Loop
    MsgBox ("ok")

End Sub
4 回复
#2
cwa99582021-04-07 13:48
这样试试看

Sub 删除行()
   
    i = ActiveCell.SpecialCells(xlLastCell).Row
    for r=i to 3 setup -1
         
        If Cells(r, 12).Value <= 0 And Cells(r, 3).Value <> "" Then
           Rows(r).Delete
        End If
   next
    MsgBox ("ok")

End Sub

[此贴子已经被作者于2021-4-7 13:55编辑过]

#3
刘学斌2021-04-07 15:14
回复 2楼 cwa9958
Sub 删除行()
   
    i = ActiveCell.SpecialCells(xlLastCell).Row
    for r=i to 3 setup -1(这一段运行错误)
         
        If Cells(r, 12).Value <= 0 And Cells(r, 3).Value <> "" Then
           Rows(r).Delete
        End If
   Next
    MsgBox ("ok")

End Sub


#4
cwa99582021-04-10 07:50
呵呵,写错了,
for r=i to 3 step -1
#5
foreach2021-04-12 09:05
代码开始时关闭刷新Application.ScreenUpdating = False,删除完成后再恢复Application.ScreenUpdating = true
还有关闭重算。
然后Cells用数组来代替,再然后删除的行批量用set aa=union(aa,Rows(r))来集合,等循环结束后,再aa.delete即可
1