PDA

View Full Version : Solved: Speed up or new code for deleteing rows



mduff
03-15-2009, 07:40 PM
Hi I found this code on the internet it is working fine but it is very slow I was wondering if anyone knows a way to speed it up or any other code to do the same thing yet faster


The key thing is need is if column G has a blank value in it then delete the row if not keep it



Sub Loop_Example()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
'We check the values in the A column in this example
With .Cells(Lrow, "g")
If Not IsError(.Value) Then
If .Value = "" Then .EntireRow.Delete
'This will delete each row with the Value "ron"
'in Column A, case sensitive.
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

thanks in advance

Digita
03-15-2009, 08:20 PM
Hi there,

Try:

Sub ZipBlanks()
Columns("G:G").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub


Hope this helps.

mduff
03-15-2009, 08:27 PM
Hi there,

Try:

Sub ZipBlanks()
Columns("G:G").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub


Hope this helps.

WOW yes it does thanks a LOT

Digita
03-15-2009, 09:20 PM
You're welcome. Glad to know it works out.

mduff
03-20-2009, 07:56 AM
Hi is there any way to use the same logic or another code to delete all rows were Column A has a #REF error?

Bob Phillips
03-20-2009, 10:08 AM
Columns("G:G").SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete

mduff
03-20-2009, 11:17 AM
TY Very Much