LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default excel macro missing worksheets

Thought I should add the collection that you need to search for the worksheets.

While I'm here I'll address the question you asked about reducing your code.
If
you use code like: Range("A1:D4").Copy Range("R12:U15") Instead of:
Range("A1:D4").Select
Selction.Copy
Range("R12:U15").Select
Selection.PasteSpecial Paste:=xlValues

It does three things at a minimum. It save you time and effort in typing
the code.
It makes the code more efficient. And it reduces the flicker and flash that
you will see on your screen.

For Each sh In ActiveWorkbook.Worksheets
If sh = Sheets("550") Then
'Insert your code for 550
End If
If sh = Sheets("725") Then
'Insert your code for 725
End if
Next



"JLGWhiz" wrote:

Something like this might work:

For Each sh In ActiveWorkbook
If sh = Sheets("550") Then
'Insert your code for 550
End If
If sh = Sheets("725") Then
'Insert your code for 725
End if
Next

You should try to eliminate some of the selects and activate like
the sample below:

Sheets("550").Columns("A:R").Select
Range("A13").EntireColumn.Hidden = False
Range("A13").Delete Shift:=xlToLeft
Range("B13").Delete Shift:=xlToLeft
Columns("E:E").ColumnWidth = 5.67



" wrote:

I have this excel file with multiple worksheets, I created a macro
that goes into each worksheet and formats a whole lot of stuff.

The problem is that some times the excel file does not have all the
worksheets included, when this happens and I try to run the macro, I
get errors because of the missing worksheets and the macro does not
finish is there a way to get the macro to skip the set of commands if
the worksheet is missing, so it would go to the next worksheet and
continue the macro? listed below is a piece of the macro, ending with
the selection of the next worksheet.

Sheets("550").Select
Columns("A:R").Select
Range("A13").Activate
Selection.EntireColumn.Hidden = False
Columns("A:A").Select
Range("A13").Activate
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
Range("B13").Activate
Selection.Delete Shift:=xlToLeft
Columns("E:E").ColumnWidth = 4.56
Columns("E:E").ColumnWidth = 5.67
Columns("E:E").Select
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight,
CopyOrigin:=xlFormatFromLeftOrAbove
Columns("V:V").Select
Selection.Cut
Columns("E:E").Select
ActiveSheet.Paste
Columns("W:W").Select
Selection.Cut
Columns("F:F").Select
ActiveSheet.Paste
Columns("S:S").Select
Selection.Cut
Columns("G:G").Select
ActiveSheet.Paste
Columns("T:T").Select
Selection.Cut
Columns("I:I").Select
ActiveSheet.Paste
Columns("AB:AB").Select
Selection.Cut
Columns("L:L").Select
ActiveSheet.Paste
Range("M6").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-1]*1.5)"
Range("M6").Select
Selection.Copy
Range("A6").Select
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Offset(, 12).Select
Range("M7", ActiveCell).Select
ActiveSheet.Paste
Range("N6").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]*2)"
Range("N6").Select
Selection.Copy
Range("A6").Select
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Offset(, 13).Select
Range("N7", ActiveCell).Select
ActiveSheet.Paste
Columns("AD:AD").Select
Application.CutCopyMode = False
Selection.Cut
Columns("Q:Q").Select
ActiveSheet.Paste
Columns("S:AD").Select
Selection.Delete Shift:=xlToLeft
Columns("Q:Q").Select
Selection.Replace What:="CA", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Select
Range("E1").Activate
Selection.NumberFormat = "@"
Sheets("725").Select


 
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
finding missing data between two worksheets Mossykel Excel Discussion (Misc queries) 10 October 30th 08 05:21 PM
missing the personal macro workbook option in excel? Todd Excel Discussion (Misc queries) 3 March 22nd 07 05:00 PM
INDIRECT.EXT problem with missing worksheets Barb Reinhardt Excel Worksheet Functions 7 October 19th 05 01:27 AM
On Error? Creates 1 missing worksheet then never detects any other missing worksheets Craigm[_35_] Excel Programming 2 August 1st 05 02:39 PM
objects missing in exixting worksheets Frank Excel Discussion (Misc queries) 0 March 10th 05 08:25 PM


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