I have code running to potentially create a large number of worksheets. As the code is running, it runs slower after each sheet can can take over 8 hours to run. How can I speed this up? I am not an expert and i am sure this code is not as efficient as it could be. What i am trying to do is copy a template worksheet, rename it using from a list and have all of the new worksheet fall in between the Begin and End tab for calculations.
Public Sub CopyIt()
Dim Counter As Integer
Dim Finalrow As Integer
Dim x As Integer
Dim IngRows As Long
Dim PctDone As Single
Dim Lastsheet As Integer
Application.Calculation = xlManual
Application.ScreenUpdating = False
Sheets("Begin").Visible = True
Sheets("End").Visible = True
Sheets("Data").Visible = True
Sheets("Data").Select
' Determine how many deptids are on Data sheet
IngRows = Range("DeptIDStart").CurrentRegion.Rows.Count
Finalrow = Range("A300").End(xlUp).row
Counter = 1
' Loop through each deptid on the data sheet
For x = 1 To Finalrow
Lastsheet = Sheets.Count
Sheets("Data").Select
DeptName = Range("A" & x).Value
' Make a copy of Begin and move to end
Sheets("Begin").Copy After:=Sheets(Lastsheet)
' rename the sheet and set G3 = to the deptid name
Sheets(Lastsheet + 1).Name = DeptName
Sheets(DeptName).Select
Range("G3").Value = DeptName
Counter = Counter + 1
PctDone = (Counter - 1) / IngRows
With UserForm2
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
Application.CutCopyMode = False
DoEvents
Next x
Unload UserForm2
Application.ScreenUpdating = True
'Sheets("Begin").Copy after:=Sheets(lastsheet)
'Sheets(lastsheet + 1).Name = "New Store 1"
Sheets("End").Move After:=Sheets(Sheets.Count)
Sheets("End").Visible = False
Sheets("Begin").Visible = False
Sheets("Data").Select
Columns("A:B").Select
Selection.ClearContents
Range("Complete") = ("Done")
Sheets("Data").Visible = False
Sheets("Total Branch").Visible = True
Call Calc
MsgBox "Worksheets have been added.", vbInformation + vbOKOnly, "Macro Complete"
Call Menu
End Sub
Public Sub CopyIt()
Dim Counter As Integer
Dim Finalrow As Integer
Dim x As Integer
Dim IngRows As Long
Dim PctDone As Single
Dim Lastsheet As Integer
Application.Calculation = xlManual
Application.ScreenUpdating = False
Sheets("Begin").Visible = True
Sheets("End").Visible = True
Sheets("Data").Visible = True
Sheets("Data").Select
' Determine how many deptids are on Data sheet
IngRows = Range("DeptIDStart").CurrentRegion.Rows.Count
Finalrow = Range("A300").End(xlUp).row
Counter = 1
' Loop through each deptid on the data sheet
For x = 1 To Finalrow
Lastsheet = Sheets.Count
Sheets("Data").Select
DeptName = Range("A" & x).Value
' Make a copy of Begin and move to end
Sheets("Begin").Copy After:=Sheets(Lastsheet)
' rename the sheet and set G3 = to the deptid name
Sheets(Lastsheet + 1).Name = DeptName
Sheets(DeptName).Select
Range("G3").Value = DeptName
Counter = Counter + 1
PctDone = (Counter - 1) / IngRows
With UserForm2
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
Application.CutCopyMode = False
DoEvents
Next x
Unload UserForm2
Application.ScreenUpdating = True
'Sheets("Begin").Copy after:=Sheets(lastsheet)
'Sheets(lastsheet + 1).Name = "New Store 1"
Sheets("End").Move After:=Sheets(Sheets.Count)
Sheets("End").Visible = False
Sheets("Begin").Visible = False
Sheets("Data").Select
Columns("A:B").Select
Selection.ClearContents
Range("Complete") = ("Done")
Sheets("Data").Visible = False
Sheets("Total Branch").Visible = True
Call Calc
MsgBox "Worksheets have been added.", vbInformation + vbOKOnly, "Macro Complete"
Call Menu
End Sub