Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Speed Up A Macro / Delete Worksheets

Any suggestions on speeding up this macro? Also, I'm working on a
macro to be able to delete these revision worksheets once I get the
information I need. However, when I use the "For i To..." it is
skipping every other worksheet (for obvious reasons). Any suggestions
on that?

Sub CopySortRev()
'
Application.ScreenUpdating = False

For i = 1 To 8
Worksheets(i).Copy After:=Worksheets(i + 8)
Sheets(i + 9).Name = Sheets(i).Name & " Rev"

Range("A2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("E2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next i
Application.ScreenUpdating = True
End Sub


Sub DeleteRev()

For i = 10 To 17

Sheets(i).Select

ActiveWindow.SelectedSheets.Delete
Sheets(i).Delete

Next i

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Speed Up A Macro / Delete Worksheets

Your code assumes there are only 9 worksheets. If that is a pre-condition
then should be ok. Otherwise you could use Worksheets.Count Also change the
sort - no need to select data first. Specify if there is a heading or not
using xlYes or xlNo changing xlGuess.

Sub CopySortRev()
Application.ScreenUpdating = False
For i = 1 To 8
Worksheets(i).Copy After:=Worksheets(i + 8)
Sheets(i + 9).Name = Sheets(i).Name & " Rev"
Range("A2:E2").Sort Key1:=Range("E2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next i
Application.ScreenUpdating = True
End Sub

The reason sub DeleteRev it is not acting on all sheets is that the control
values are increasing by 1 but you are removing the sheet at the same time.
Change the code to start at 17 and count down to 10. I added the
displayalerts to suppress the deletion warnings if you require this.

Sub DeleteRev()
Application.DisplayAlerts = False
For i = 17 To 10 step -1
Sheets(i).Delete
Next i
Application.DisplayAlerts = True
End Sub



--
Cheers
Nigel



wrote in message
oups.com...
Any suggestions on speeding up this macro? Also, I'm working on a
macro to be able to delete these revision worksheets once I get the
information I need. However, when I use the "For i To..." it is
skipping every other worksheet (for obvious reasons). Any suggestions
on that?

Sub CopySortRev()
'
Application.ScreenUpdating = False

For i = 1 To 8
Worksheets(i).Copy After:=Worksheets(i + 8)
Sheets(i + 9).Name = Sheets(i).Name & " Rev"

Range("A2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Sort Key1:=Range("E2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Next i
Application.ScreenUpdating = True
End Sub


Sub DeleteRev()

For i = 10 To 17

Sheets(i).Select

ActiveWindow.SelectedSheets.Delete
Sheets(i).Delete

Next i

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
Help, need to speed up this macro retseort Excel Discussion (Misc queries) 3 January 12th 06 12:33 PM
Macro Speed Don Lloyd Excel Programming 4 July 28th 05 06:02 PM
Speed-up a macro! maca[_3_] Excel Programming 3 July 15th 05 06:40 PM
Speed up macro rn Excel Discussion (Misc queries) 3 February 21st 05 01:25 PM
Speed-up macro Thomas[_7_] Excel Programming 2 October 2nd 03 05:55 AM


All times are GMT +1. The time now is 05:38 AM.

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

About Us

"It's about Microsoft Excel"