Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Locate a change in Col

I have a bit of code that deletes rows that do not match a certain criteria:

For i = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
If Cells(i, "D").Value < Range("D2").Value Then
Rows(i).Delete
End If
Next i

This works but it takes forever, sometimes has to delete 1500 rows.

I am looking for something that will identify the first row in Col D that
does not match D2 and then offsets to the same row in Col A where I will use
the following:

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

Any Suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default Locate a change in Col

have you tried to switch the calculation to manual before executing your code
and then put it back to automatic?
it generally works and reduce the time dramatically

Sub CalcManual()

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

End Sub



Sub CalcAutomatic()
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Calculate

End Sub

--
caroline


"rlee1999" wrote:

I have a bit of code that deletes rows that do not match a certain criteria:

For i = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
If Cells(i, "D").Value < Range("D2").Value Then
Rows(i).Delete
End If
Next i

This works but it takes forever, sometimes has to delete 1500 rows.

I am looking for something that will identify the first row in Col D that
does not match D2 and then offsets to the same row in Col A where I will use
the following:

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

Any Suggestions?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Locate a change in Col

Thank You Caroline!!! Works like a charm!

"caroline" wrote:

have you tried to switch the calculation to manual before executing your code
and then put it back to automatic?
it generally works and reduce the time dramatically

Sub CalcManual()

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

End Sub



Sub CalcAutomatic()
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Calculate

End Sub

--
caroline


"rlee1999" wrote:

I have a bit of code that deletes rows that do not match a certain criteria:

For i = Cells(Rows.Count, "D").End(xlUp).Row To 2 Step -1
If Cells(i, "D").Value < Range("D2").Value Then
Rows(i).Delete
End If
Next i

This works but it takes forever, sometimes has to delete 1500 rows.

I am looking for something that will identify the first row in Col D that
does not match D2 and then offsets to the same row in Col A where I will use
the following:

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

Any Suggestions?

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
How to locate the value? Eric Excel Discussion (Misc queries) 1 August 30th 09 06:27 PM
STILL CAN'T LOCATE XML emi New Users to Excel 1 July 24th 07 11:04 PM
Why can't locate the file? TimN Excel Programming 4 August 18th 06 05:56 PM
locate and change hidden lines Todd -marietta Excel Worksheet Functions 1 December 4th 05 12:52 AM
Locate max value cell Kevin Excel Programming 1 December 10th 03 05:05 PM


All times are GMT +1. The time now is 08:26 PM.

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"