VBA to duplicate and name sheet according to list

fazzaf

New Member
Joined
Aug 4, 2023
Messages
2
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi, I have the following VBA
VBA Code:
Sub CopyTemplate()
    Dim wTemplate As Worksheet
    Dim wLIST As Worksheet
    Dim wCopy As Worksheet
    Dim r As Long
    Dim m As Long
    Application.ScreenUpdating = False
    Set wTemplate = Worksheets("Template")
    Set wLIST = Worksheets("Lookup")
    m = wLIST.Range("F1").End(xlDown).Row
    For r = 2 To m
        wTemplate.Copy After:=Worksheets(Worksheets.Count)
        Worksheets(Worksheets.Count).Name = wLIST.Range("F" & r).Value
    Next r
    Application.ScreenUpdating = True
End Sub

The list can be found from F1 to F23 (including headers, so data starts from F2), on sheet "Lookup"
And the sheet being copied and renamed according to the list is named "Template"

When running, the sheets paste as Template (n), 23 times, when previously it used to rename the copied sheet according to my list.

This used to work, but I have made some changes to Template, instead of being 1 page, it is now 3 pages (I set up print areas) and I'm not sure if this is causing the bug or not.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Apologies for double post Template ( n ), where n is number of rows in my list
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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