Sub RunSim()
Dim LastRow As Long, rng1 As Range, rng2 As Range
With Application
'.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
'Runs through a unique list of Business Areas and creates a new file for each
'-------------------------'-----------------------------------------------------------
For Each a In Range("Ba") 'change "Ba" to "Cc" for templates by cost centre & business area'
'-------------------------------------------------------------------------------'
' Update Workbooks("----").Activate after you make any changes to the file name '
'-------------------------------------------------------------------------------'
Workbooks("Master Template v0.1.xls").Activate
Sheets(Array("Cover", "Charts", "Var", "Bs", "Bs Fcst", "Bs Plan", "Bs Bud", "P&L", "P&L Fcst", _
"P&L Plan", "P&L Bud", "Act", "Bud", "Sim Tbl")).Copy
Sheets("BS").Range("B4").Value = a.Value
'Deletes actuals from the new file if the transaction doesn't correspond with the cost centre
'-------------------------------------------------------------------------------------
LastRow = WorksheetFunction.CountA(Sheets("Act").Range("A:A"))
Set rng1 = Sheets("Act").Range("E2:E" & LastRow)
Set rng2 = Sheets("Act").Range("E1:E" & LastRow)
rng2.AutoFilter field:=5, Criteria1:="<>" & a.Value
rng1.SpecialCells(xlCellTypeVisible).EntireRow.Delete
'Deletes budget from the new file if the transaction doesn't correspond with the cost centre
'-------------------------------------------------------------------------------------
LastRow = WorksheetFunction.CountA(Sheets("Bud").Range("A:A"))
Set rng1 = Sheets("Bud").Range("E2:E" & LastRow)
Set rng2 = Sheets("Bud").Range("E1:E" & LastRow)
rng2.AutoFilter field:=5, Criteria1:="<>" & a.Value
rng1.SpecialCells(xlCellTypeVisible).EntireRow.Delete
'Saves the file with a unique name
'---------------------------------------------------------------------------------------------
ActiveWorkbook.SaveAs Filename:="C:\Budget Template " & a & ".xls", FileFormat:=xlNormal, _
Password:="", writerespassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
'Recalculates all formula
'---------------------------------------------------------------------------------------------
Sheets("Cover").Select
Application.Calculation = xlCalculationAutomatic
Calculate
'Resaves the file and then closes it
'----------------------------------------------------------------------------------------------
With ActiveWorkbook
.Save
.Close
End With
Next a
MsgBox ("Done!")
'Application.ScreenUpdating = True
End Sub