P
pidoling
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
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