Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Slow Macro - Delete Row Based on Condition-Modified Ron DeBruin Ma

Hello,

I have modified Ron DeBruin's macro that deletes an entire row based on a
condition. When I test the macro on a small sample (less than 100) it works
quickly (I am deleting any row that does not have "Central Metro" in column
D. When I run it on my full data set (4000 rows), it runs for over 10
minutes but never completes. Ultimately I have forced it to stop.

Is there a way to speed this up and work with the 4000 rows? Is there
another way to program it?

I have pasted the macro below.

Thanks in advance.
-Scott

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 = "2"
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, "D")

If Not IsError(.Value) Then

If .Value < "Central Metro" 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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Slow Macro - Delete Row Based on Condition-Modified Ron DeBruin Ma

Hi,

10k rows on my PC which is nothing special took 8 seconds so maybe something
else is going on. Do you have any worksheet event code that these deletions
are firing? Try this change at the start of the code to disable events

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

don't forget to re-enable at the end

..EnableEvents = True

Mike

"ScottMSP" wrote:

Hello,

I have modified Ron DeBruin's macro that deletes an entire row based on a
condition. When I test the macro on a small sample (less than 100) it works
quickly (I am deleting any row that does not have "Central Metro" in column
D. When I run it on my full data set (4000 rows), it runs for over 10
minutes but never completes. Ultimately I have forced it to stop.

Is there a way to speed this up and work with the 4000 rows? Is there
another way to program it?

I have pasted the macro below.

Thanks in advance.
-Scott

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 = "2"
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, "D")

If Not IsError(.Value) Then

If .Value < "Central Metro" 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Slow Macro - Delete Row Based on Condition-Modified Ron DeBrui

Mike,

I disabled events, but still the macro is running slowly. I tested it
running 500, 1000, 1500, 2000, and 2500 rows to see what the speed was.
Everything was fine until I hit 2000 rows. 2500 rows never completed. When
I interrupt the macro, I can see that it has processed some of the rows, but
again, well over 10+ minutes and it never finishes.

I pasted the revised macro (based on your recommendation) so you can see
what I edited.

Any further thoughts?

Thanks in advance.

-Scott


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
.EnableEvents = 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 = "2"
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, "D")

If Not IsError(.Value) Then

If .Value < "Central Metro" 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
.EnableEvents = True
End With

End Sub


"Mike H" wrote:

Hi,

10k rows on my PC which is nothing special took 8 seconds so maybe something
else is going on. Do you have any worksheet event code that these deletions
are firing? Try this change at the start of the code to disable events

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

don't forget to re-enable at the end

.EnableEvents = True

Mike

"ScottMSP" wrote:

Hello,

I have modified Ron DeBruin's macro that deletes an entire row based on a
condition. When I test the macro on a small sample (less than 100) it works
quickly (I am deleting any row that does not have "Central Metro" in column
D. When I run it on my full data set (4000 rows), it runs for over 10
minutes but never completes. Ultimately I have forced it to stop.

Is there a way to speed this up and work with the 4000 rows? Is there
another way to program it?

I have pasted the macro below.

Thanks in advance.
-Scott

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 = "2"
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, "D")

If Not IsError(.Value) Then

If .Value < "Central Metro" 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Slow Macro - Delete Row Based on Condition-Modified Ron DeBrui

There are a lot of other examples on the site

Try the Filter or Union example for this situation
http://www.rondebruin.nl/delete.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"ScottMSP" wrote in message ...
Mike,

I disabled events, but still the macro is running slowly. I tested it
running 500, 1000, 1500, 2000, and 2500 rows to see what the speed was.
Everything was fine until I hit 2000 rows. 2500 rows never completed. When
I interrupt the macro, I can see that it has processed some of the rows, but
again, well over 10+ minutes and it never finishes.

I pasted the revised macro (based on your recommendation) so you can see
what I edited.

Any further thoughts?

Thanks in advance.

-Scott


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
.EnableEvents = 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 = "2"
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, "D")

If Not IsError(.Value) Then

If .Value < "Central Metro" 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
.EnableEvents = True
End With

End Sub


"Mike H" wrote:

Hi,

10k rows on my PC which is nothing special took 8 seconds so maybe something
else is going on. Do you have any worksheet event code that these deletions
are firing? Try this change at the start of the code to disable events

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

don't forget to re-enable at the end

.EnableEvents = True

Mike

"ScottMSP" wrote:

Hello,

I have modified Ron DeBruin's macro that deletes an entire row based on a
condition. When I test the macro on a small sample (less than 100) it works
quickly (I am deleting any row that does not have "Central Metro" in column
D. When I run it on my full data set (4000 rows), it runs for over 10
minutes but never completes. Ultimately I have forced it to stop.

Is there a way to speed this up and work with the 4000 rows? Is there
another way to program it?

I have pasted the macro below.

Thanks in advance.
-Scott

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 = "2"
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, "D")

If Not IsError(.Value) Then

If .Value < "Central Metro" 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to delete rows based on a condition marcia2026 Excel Programming 9 October 31st 09 10:54 AM
Delete Rows based on condition Vic Excel Discussion (Misc queries) 2 August 18th 09 08:54 PM
how to delete a row based on a condition ya Excel Programming 2 December 17th 08 03:59 PM
Macro to delete rows based on a condition Darrilyn Excel Worksheet Functions 1 September 6th 07 12:12 AM
Delete Columns based on a condition Joel Mills Excel Programming 3 August 6th 04 07:21 PM


All times are GMT +1. The time now is 01:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"