I have an Excel spreadsheet with over 2000 rows of data and need to delete any rows that contain a 'x' in a certain column (approximately 2 in every 7). At the moment am looping through from the end of the data but it is sooooo slooooooooooow :-( Anybody got any better methods?
I've switched off autocalc and screen refresh to try and speed it up, but this still takes an age and a half (the machine I'm using isn't particularly fast)
PLEASE if someone can help....even if it's just to stop my monitor getting thrown on the floor out of sheer desperation ;-)
This is the code that I'm using at the moment:
Sub Remove_rows_with_x()
'Switch off auto calculate in Excel to speed up process
With Application
.Calculation = xlManual
.MaxChange = 0.001
.CalculateBeforeSave = False
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = False
Sheet3.Select
Dim intCounter As Integer, intLastRow As Integer
intLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For intCounter = intLastRow To 1 Step -1
If Not IsEmpty(Cells(intCounter, 3)) And _
Cells(intCounter, 3).Value = "x" Then
Rows(intCounter).Delete
End If
Next intCounter
Sheet1.Select
'Switch autocalculate back on
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True
End Sub
I've switched off autocalc and screen refresh to try and speed it up, but this still takes an age and a half (the machine I'm using isn't particularly fast)
PLEASE if someone can help....even if it's just to stop my monitor getting thrown on the floor out of sheer desperation ;-)
This is the code that I'm using at the moment:
Sub Remove_rows_with_x()
'Switch off auto calculate in Excel to speed up process
With Application
.Calculation = xlManual
.MaxChange = 0.001
.CalculateBeforeSave = False
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = False
Sheet3.Select
Dim intCounter As Integer, intLastRow As Integer
intLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For intCounter = intLastRow To 1 Step -1
If Not IsEmpty(Cells(intCounter, 3)) And _
Cells(intCounter, 3).Value = "x" Then
Rows(intCounter).Delete
End If
Next intCounter
Sheet1.Select
'Switch autocalculate back on
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True
End Sub