tbablue
Active Member
- Joined
- Apr 29, 2007
- Messages
- 488
- Office Version
- 365
- Platform
- Windows
Sub CreateWorksheets(Names_Of_Sheets As Range)
Dim Nf_Sheets_to_be_Added As Integer
Dim Sheet_Name As String
Dim i As Integer
Nf_Sheets_to_be_Added = Names_Of_Sheets.Rows.Count
For i = 1 To Nf_Sheets_to_be_Added
Sheet_Name = Names_Of_Sheets.Cells(i, 1).Value
'Only add sheet if it doesn't exist already and the name is longer than zero characters
If (Sheet_Exists(Sheet_Name) = False) And (Sheet_Name <> "") Then
Worksheets.Add().Name = Sheet_Name
Sheets("sample detail sheet").Select
Selection.Copy
Sheets("sample").Select
ActiveSheet.Paste
End If
Next i
End Sub
After help from this forum my current code is above. I can create new sheets and name them - as per the items in specified range C4:C13. So far so good.
But now I want to apply the same formatting to all my newly created sheets - and to this end thought it easier to copy and paste my formatting from a template sheet', "sample detail sheet".
The code in red is from the macro recorder but I'm struggling to implement it in the way I want; I can't figure out how to paste to anything but the active sheet - I need to paste the selected formatting to all my new sheets.
Any help welcomed.
Dim Nf_Sheets_to_be_Added As Integer
Dim Sheet_Name As String
Dim i As Integer
Nf_Sheets_to_be_Added = Names_Of_Sheets.Rows.Count
For i = 1 To Nf_Sheets_to_be_Added
Sheet_Name = Names_Of_Sheets.Cells(i, 1).Value
'Only add sheet if it doesn't exist already and the name is longer than zero characters
If (Sheet_Exists(Sheet_Name) = False) And (Sheet_Name <> "") Then
Worksheets.Add().Name = Sheet_Name
Sheets("sample detail sheet").Select
Selection.Copy
Sheets("sample").Select
ActiveSheet.Paste
End If
Next i
End Sub
After help from this forum my current code is above. I can create new sheets and name them - as per the items in specified range C4:C13. So far so good.
But now I want to apply the same formatting to all my newly created sheets - and to this end thought it easier to copy and paste my formatting from a template sheet', "sample detail sheet".
The code in red is from the macro recorder but I'm struggling to implement it in the way I want; I can't figure out how to paste to anything but the active sheet - I need to paste the selected formatting to all my new sheets.
Any help welcomed.