PDA

View Full Version : Execute macro on all sheets but last 6



ssinghal
01-08-2007, 07:56 AM
I want to execute the following macro on all sheets in a workbook except the last 6. The workbook has anywhere from 50 to 100 sheets. I created the macro using the recording tool as I am not that great a programmer. I appreciate the help.

Sub forecast()
'
' forecast Macro
' Macro recorded 10/31/2006 by ssinghal
'
' Keyboard Shortcut: Ctrl+f
'
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("M:P").Select
With Selection
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Selection.ColumnWidth = 6.57
Columns("H:H").Select
Selection.Insert Shift:=xlToRight
Range("H1").Select
ActiveCell.FormulaR1C1 = "Occupancy"
With ActiveCell.Characters(Start:=1, Length:=9).Font
.Name = "Tahoma"
.FontStyle = "Bold"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 11
End With
Range("D1").Select
ActiveCell.FormulaR1C1 = "Day"
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "Tahoma"
.FontStyle = "Bold"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 11
End With
Range("D2").Select
ActiveCell.FormulaR1C1 = "=TEXT(DATEVALUE(RC[-1]),""ddd"")"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D70"), Type:=xlFillDefault
Range("D2:D70").Select
Range("H2").Select
ActiveCell.FormulaR1C1 = "=VALUE(RC[-1])"
Range("H2").Select
Selection.Style = "Percent"
Selection.AutoFill Destination:=Range("H2:H70"), Type:=xlFillDefault
Range("H2:H70").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="0.75", Formula2:="0.97"
Selection.FormatConditions(1).Interior.ColorIndex = 44
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="0.9701"
Selection.FormatConditions(2).Interior.ColorIndex = 3
Range("A1").Select
Columns("G:G").Select
Selection.EntireColumn.Hidden = True

lucas
01-08-2007, 08:00 AM
It seems you are just formatting your pages...why not use a template sheet or are they already full of data?

ssinghal
01-08-2007, 08:03 AM
The file I am formatting is generated every day and emailed to 20 people in my company. I would like to build a macro that can be run to format it. I am also inserting rows and copying data in the macro.