[VBA] Duplicate sheets & update sheet name and two cells based on list

bnbcat

New Member
Joined
Apr 27, 2016
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have the handy code below to duplicate a sheet multiple times and update the sheet name based on a list of values.

Sub CreateSheetsFromAList()
Dim Location As Range
Dim dic As Object, c As Range
Dim k As Variant, tmp As String

Set dic = CreateObject("scripting.dictionary")
Set Location = Sheets("Sheet3").Range("A1")
Set Location = Range(Location, Location.End(xlDown))

For Each c In Location
tmp = Trim(c.Value)
If Len(tmp) > 0 Then dic(tmp) = dic(tmp) + 1
Next c

For Each k In dic.keys
Sheets("COUNTRY").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = k ' renames the new worksheet


Next k


End Sub


I need to add to this so that not only are the sheet names updated, but values in 2 different locations are updated as well, also based on a list.

IE:

Value list:

Sheet NameCell A1Cell A3
USA_AppleUSAApple
USA_BananaUSABanana
CA_AppleCanadaApple

So when the sheets are duplicated, the first sheet will be titled "USA_Apple" with cell A1 containing "USA" and cell A3 containing "Apple", the second sheet titled "USA_Banana" with cell A1 containing "USA" and cell A3 containing "Banana," and the third sheet titled "CA_Apple" with cell A1 containing "Canada" and cell A3 containing "Apple."

All help would be very appreciated!!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Can you have duplicate values in col A?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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