LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 594
Default Can this code be speeded up?

Hi All.......
Below is code that works fine, it just takes a long time to run and I was
hoping someone could give me an idea how to speed it up.....like by cutting
the time in half or better......the idea behind it is that on a 3500 row
database, each row has a date in column Q that is the first day of the month
only. This macro effectively deletes all rows whose date equals the oldest
date in column Q. Incidently, if I use "delete" instead of "clearcontents
and then sort", it causes a reduction of the size of the database each time
it's run, which is unacceptable.

Here's the code:
Sub DeleteTheOldestMonth()
Dim lastrow As Long, r As Long
Dim oldest As String
Range("data!k1").Value = "=min(ALL12!Q13:Q10000)" 'col Q contains dates
'using the first day of each month only
oldest = Range("data!k1").Value
Sheets("ALL12").Select
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For r = lastrow To 13 Step -1

If Cells(r, "Q").Value Like oldest Then
Rows(r).EntireRow.ClearContents
End If
Next r

'Sort the database, firstkey col A, secondkey col Q to eliminate blank rows
'without changing the RANGE of the database, A12:S10000
Range("A12:z10000").Select
Selection.Sort Key1:=Range("A12"), Order1:=xlAscending,
Key2:=Range("Q12" _
), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=
_
False, Orientation:=xlTopToBottom

Range("A12").Select
End Sub

TIA
Vaya con Dios,
Chuck, CABGx3




 
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
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
Can the "Save" process be speeded up? JK Excel Programming 2 September 4th 04 03:02 PM


All times are GMT +1. The time now is 10: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"