Create the sheets with cells range then after paste the "Template" sheet in New created Sheets

santoshloka

Board Regular
Joined
Aug 31, 2017
Messages
125
Hello Evreyone

I need little help to create macro.

Create sheets with cells range
copy the template sheet
paste in cells range

"Please see the Highlighted Red Color"


'Name macro
Sub CreateSheets()

'Dimension variables and declare data types
Dim rng As Range
Dim cell As Range

'Enable error handling
On Error GoTo Errorhandling

'Show inputbox to user and prompt for a cell range
Set rng = Application.InputBox(Prompt:="Select cell range:", _
Title:="Create sheets", _
Default:=Selection.Address, Type:=8)

'Iterate through cells in selected cell range
For Each cell In rng

'Check if cell is not empty
If cell <> "" Then

'Insert worksheet and name the worksheet based on cell value
Sheets.Add.Name = cell
Sheets("Template").Copy After:=Sheets("cell").Paste
End If

'Continue with next cell in cell range
Next cell


'Go here if an error occurs
Errorhandling:

'Stop macro
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this:

VBA Code:
'Insert worksheet and name the worksheet based on cell value
Sheets("Template").Copy After:=Sheets("Template")
Sheets("Template (2)").Name = cell
 
Upvote 0
Try this:

VBA Code:
'Insert worksheet and name the worksheet based on cell value
Sheets("Template").Copy After:=Sheets("Template")
Sheets("Template (2)").Name = cell
Thanks for your reply

it is creating new "Template" sheet instead of range sheets

rng=Tab1,Tab2
i want Template sheet to paste in Tab1 and Tab2

VBA Code:
'Name macro
Sub CreateSheets()
 
'Dimension variables and declare data types
Dim rng As Range
Dim cell As Range

'Enable error handling
On Error GoTo Errorhandling
 
'Show inputbox to user and prompt for a cell range
Set rng = Application.InputBox(Prompt:="Select cell range:", _
Title:="Create sheets", _
Default:=Selection.Address, Type:=8)
 
'Iterate through cells in selected cell range
For Each cell In rng
 
    'Check if cell is not empty
    If cell <> "" Then
 
        'Insert worksheet and name the worksheet based on cell value
        Sheets.Add.Name = cell
       Sheets("Template").Copy After:=Sheets("Template")
        Sheets("Template (2)").Name = cell
    End If
 
'Continue with next cell in cell range
Next cell

 
'Go here if an error occurs
Errorhandling:
 
'Stop macro
End Sub
 
Upvote 0
I guess I misunderstood - or perhaps I was unclear. I thought you wanted to make copies of the template sheet and name each based on the select range.

Comment out the following line and try again and I think it will do what you want:

Sheets.Add.Name = cell
 
Upvote 0
1627489313903.png


1627489246810.png
 
Upvote 0
Template sheet have some data.(better to copy whole Template sheet in Tab1,Tb2...etc)

The data should copy in all tabs like you shown in picture
 
Upvote 0
It does that. In my example, I just have "My Template" in A1 as the data. It is in each new tab.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top