Forum Discussion
kvhpkh
Jan 12, 2023Copper Contributor
How can I copy and paste multiple sheets at once while keeping my row/column formatting?
I have tried many different things and nothing is working. I want to copy the first sheet and pasted it into the other 25 sheets, while keeping the row/column formatting (as well as all the formatti...
- Jan 14, 2023
Try this version:
Sub CreateSheets() Dim y As Long Dim w As Long Dim d As Date Dim i As Long Dim s As Worksheet y = InputBox(Prompt:="Enter the year", Default:=Year(Date) + 1) w = Weekday(DateSerial(y, 1, 1), vbSaturday) d = DateSerial(y, 1, 1) + 14 - w Application.ScreenUpdating = False Application.DisplayAlerts = False For i = Worksheets.Count To 2 Step -1 Worksheets(i).Delete Next i Set s = Worksheets(1) For i = 1 To 25 s.Copy After:=Worksheets(Worksheets.Count) Worksheets(Worksheets.Count).Name = Format(d + 14 * i, "mmm d") Next i Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
kvhpkh
Jan 14, 2023Copper Contributor
I tried that and it asked me "what year?" When I entered 2023 it gave me a run time error 1004 and said "that name has been taken, try another".
HansVogelaar
Jan 14, 2023MVP
Try this version:
Sub CreateSheets()
Dim y As Long
Dim w As Long
Dim d As Date
Dim i As Long
Dim s As Worksheet
y = InputBox(Prompt:="Enter the year", Default:=Year(Date) + 1)
w = Weekday(DateSerial(y, 1, 1), vbSaturday)
d = DateSerial(y, 1, 1) + 14 - w
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = Worksheets.Count To 2 Step -1
Worksheets(i).Delete
Next i
Set s = Worksheets(1)
For i = 1 To 25
s.Copy After:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = Format(d + 14 * i, "mmm d")
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
- kvhpkhJan 14, 2023Copper ContributorThat did the trick! Thanks!