删除包含数据的行:缓冲区问题

我需要删除大约10000行C列中包含“$”的所有行。 我已经尝试过,但需要永久完成。 有人有一个更快或更有效的方式来做到这一点?

Last = Cells(Rows.Count, "C").End(xlUp).Row For i = Last To 1 Step -1 If (Cells(i, "C").Value) = "$" Then Cells(i, "A").EntireRow.Delete End If Next i 

尝试使用.Find()

 Dim rng As Range 'Application.ScreenUpdateing = False 'don't enable this until you're sure the 'works correctly Set rng = Range.Columns("C").Find(what:="$", LookIn:=xlValues) While Not rng Is Nothing rng.EntireRow.Delete Set rng = Range.Columns("C").Find(what:="$", LookIn:=xlValues) Wend Set rng = Nothing Application.ScreenUpdateing = False 

您可能需要为.Find()调用添加一些额外的参数,以指定您正在查找的内容 – 它使用的参数与“ Find对话框中设置的参数完全相同,除非您在代码中覆盖它们,并在代码中设置它们会在下次打开“ Find对话框时反映出来,所以您必须非常小心。

您可以在操作时closures一些无用的function,我添加了一个定时器,以便您可以进行比较。

第一个选项,删除同样的动作,没有数组:

 Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Dim TimingT As Long TimingT = Time last = Cells(Rows.Count, "C").End(xlUp).Row For i = last To 1 Step -1 If (Cells(i, "C").Value) = "$" Then Cells(i, "A").EntireRow.Delete End If Next i Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True MsgBox "Total duration of operation : " & Format(Time - TimingT, "hh:mm:ss"), vbInformation, "Procedure finished" 

第二个选项,用一个数组:

 Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Dim LastR As Long Dim TimingT As Long TimingT = Time Dim ToDel() LastR = Cells(Rows.Count, "C").End(xlUp).Row ReDim ToDel(LastR) For i = 1 To UBound(ToDel) ToDel(i) = InStr(1, Cells(i, "C"), "$") Next i For i = UBound(ToDel) To 1 Step -1 If ToDel(i) <> 0 Then Rows(i).EntireRow.Delete End If Next i Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True MsgBox "Total duration of operation : " & Format(Time - TimingT, "hh:mm:ss"), vbInformation, "Procedure finished" 

第三种select,clearcontents,然后sorting(没有这样做,但可能会有趣…)