Excel auto worksheet title function

gwoolley0302

Board Regular
Joined
May 13, 2014
Messages
55
Hi everyone, I'm looking to automate the process of repeating an excel worksheet (which is set up with various tables and formulas) for various countries. I have a referenced list of countries set up in worksheet 1. So for example: in worksheet 2 I have a sheet set up for Albania - and I want to repeat this for another 100 countries. . Can I use the reference list of countries to auto-repeat worksheet 2 for worksheets 3 - 102 and auto-title the worksheet tabs? (E.g. Brazil, Canada, Chile..............) Really appreciate your help.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Providing there's no illegal characters in the country names and all sheets are Worksheets (normal sheets - not chart sheets or anything else) and your original sheet is called 'Template':

.... edit.... and there's no duplicate country names or blank cells in the country list.....

Code:
Public Sub Test()

    Dim rCountryRange As Range
    Dim rCountry As Range
    Dim wrkSht As Worksheet
    
    With ThisWorkbook 'ThisWorkbook is the Excel file that this code is in.
    
        Set rCountryRange = .Worksheets("Sheet1").Range("A1:A6") 'Extend the range to cover all countries.
        
        For Each rCountry In rCountryRange
            .Worksheets("Template").Copy After:=Sheets(.Worksheets.Count)
            .Worksheets(.Worksheets.Count).Name = rCountry.Value
        Next rCountry
    
    End With


End Sub
 
Upvote 0
Hi Darren - sorry complete Macro novice here. If I also wanted to populate every copied worksheet with the respective country name in cells A2:A10 - what would I insert above and whereabouts? Greg
 
Upvote 0
No problem,

Just add these two lines before the Next rCountry line
Code:
.Worksheets(.Worksheets.Count).Range("A2:A10").FormulaArray = rCountry.Value
.Worksheets(.Worksheets.Count).Columns(1).AutoFit

The second line isn't really necessary, but makes sure you can read the country name.
 
Upvote 0

Forum statistics

Threads
1,214,655
Messages
6,120,760
Members
448,991
Latest member
Hanakoro

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