【问题标题】:Delete Mulitple Rows Based on Date根据日期删除多行
【发布时间】:2019-03-15 15:35:21
【问题描述】:

我创建了一个宏,在其中我根据“C”列中的日期删除每一行。我在使用宏时遇到问题,因为它会遍历每一行并逐行删除它们,而不是一次全部删除。有什么办法可以加快这个过程,这样它就不会需要 30 分钟才能运行。顺便说一下,文件很大。

Sub DeleteRowsBeforeCutoff()
    Application.ScreenUpdating = False

    NumRows = Range("C3", Range("C3").End(xlDown)).Rows.Count
    Range("A1").Select
    For x = 3 To NumRows
        If Cells(x, 3) < [K1] Then
            Cells(x, 3).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
End Sub

【问题讨论】:

  • 运行循环向后

标签: excel vba


【解决方案1】:

正如@Gary 所写,代码将向后循环, 我尝试了你的代码(更新)广告我将每一行删除到一个 25K 范围的行中, 这是结果: 我的代码:00:00:03:123 乔码:00:00:14:1214

两个代码:

Sub testJoe()
Dim startTime As Single
Dim i As Long
startTime = Time()
For i = Range("C2").End(xlDown).Row To 2 Step -1
    If Cells(i, 3) = 3 Then Rows(i).EntireRow.Delete
Next
Debug.Print Format(Time() - startTime, "HH:nn:ss:ms")
End Sub

Sub mytest()
Dim startTime As Single, rang As Range, sh As Worksheet
startTime = Time()
Set sh = ActiveSheet
sh.UsedRange.AutoFilter Field:=3, _
                        Criteria1:="=3", _
                        VisibleDropDown:=False
Set rang = sh.UsedRange.Offset(1, 0)
Set rang = rang.Resize(rang.Rows.Count - 1)
Set rang = rang.SpecialCells(xlCellTypeVisible)
rang.EntireRow.Delete
Selection.AutoFilter
Debug.Print Format(Time() - startTime, "HH:nn:ss:ms")
End Sub

【讨论】:

    猜你喜欢
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    相关资源
    最近更新 更多