Rename copied sheets based on list that skips cells

TrafficEG

New Member
Joined
Aug 1, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a workbook that has two tabs to start with "Input" and "Template". I have a macro already developed that will copy "Template" based on a value I input but I need those copied sheets to be renamed based on a value that appears in A13, A23, A33, etc.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Where exactly do these values appear?
Is there some range you want it to loop through?
 
Upvote 0
My plan is that you will run the first macro, which copies the "Template" sheet based on a number you input. Then you would run a second macro that will rename the sheets made from the first macro with values that are in the "Input" sheet starting at cell A13 and every 10 cells below that (ie cell A23, A33, etc) until it runs out of sheets to rename.
 
Upvote 0
Why not just have one macro that starts in cell A13, and copies the template, renames it, and then moves down 10 row to A23, etc until the end of the data in column A on the Input sheet?
 
Upvote 0
I could not get a macro to do that and work :ROFLMAO:. I am new to VBA coding.
 
Upvote 0
Give this a try:
VBA Code:
Sub MyInsertNewSheets()

    Dim wsTmp As Worksheet
    Dim wsInp As Worksheet
    Dim wsNew As Worksheet
    Dim r As Long
    Dim lr As Long

    Application.ScreenUpdating = False

'   Set worksheet variables
    Set wsTmp = Sheets("Template")
    Set wsInp = Sheets("Input")

'   Find last row with data in column A on Input sheet
    lr = wsInp.Cells(Rows.Count, "A").End(xlUp).Row

'   Loop through column A on Input sheet, starting in A13 jumping 10 rows at a time
    For r = 13 To lr Step 10
'       Add new sheet after last sheet
        Sheets.Add After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
'       Capture new sheet
        Set wsNew = ActiveSheet
'       Copy template to new sheet
        wsTmp.Cells.Copy
        wsNew.Activate
        ActiveSheet.Paste
        Application.CutCopyMode = False
'       Rename new sheet
        wsNew.Name = wsInp.Cells(r, "A")
    Next r

    Application.ScreenUpdating = True
    
    MsgBox "Macro complete!"
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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