polarisking
Member
I'm trying to delete several thousand entire rows, and it's taking way too long. I've turned off screenupdating and auto calculation with noticing much improvement.
Any ideas?
Any ideas?
Do While Range("A" & ctrRow) <> 0
If Range("C" & ctrRow) < Range("CurrentDateMinus10") Then
Cells(ctrRow, "A").EntireRow.Delete
Debug.Print "Row" & ctrRow
End If
ctrRow = ctrRow + 1
Loop
Dim SomeValue As Double
Dim i As Long
Dim lastRow As Long
'Store this in a variable, so we don't have to
'keep reading the cell every time
SomeValue = Range("CurrentDateMinus10").Value
'Define where the last record is at
With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Step through rows backwards, since everytime we delete a row
'all the rows below will shift up a row, messing up our count
'if we started at top
Application.ScreenUpdating = False
For i = lastRow To 2 Step -1
With Cells(i, "C")
If .Value < SomeValue Then
.EntireRow.Delete
Debug.Print "Row " & i
End If
End With
Next i
Application.ScreenUpdating = True
Sub proclearCells()
Dim rngTable As Range
Dim ws As Worksheet
Dim StartCell As Range
Const ColumntoFilter1 As Integer = 3
'Turn Screen Updating off
ScreenUpdating = False
Set ws = Worksheets("RKS MV")
ws.Select
'Set the starting position (Top-left most position) of your data range
Set StartCell = ws.Range("A1")
'Turn off autofilter in case it's already active
ws.AutoFilterMode = False
'Define data table
Set rngTable = StartCell.CurrentRegion
'Filter and delete data
With rngTable
.AutoFilter Field:=ColumntoFilter1, Criteria1:="<" & Range("CurrentDateMinus10")
.Offset(1, 0).EntireRow.Delete
End With
'Turn filters off again
ws.AutoFilterMode = False
'Turn Screen Updating on again
ScreenUpdating = False
End Sub
Option Explicit
Sub AutoMotor() 'RKS MV sheet is sheet1
Sheet1.Range("C2", Sheet1.Range("C65536").End(xlUp)).AutoFilter 1, _
"<" & CLng(DateValue(Range("CurrentDateMinus10")))
Sheet1.Range("C2", Sheet1.Range("C65536").End(xlUp)).EntireRow.Delete
Sheet1.[c1].AutoFilter
End Sub