Macro to create worksheets from template ws W/ Dynamic range with duplicates in range

balla506

New Member
Joined
Sep 10, 2012
Messages
32
Hi,


I am trying to make this macro not use a named range but a dynamic range (so later on if a new customer needs to be added they can and it will create the worksheet). Also there are duplicate customers in the range which is on the "'reference" worksheet. If it sees a duplicate and a worksheet is already created for it, it should skip over to the next one. The customer names are in column F on the reference sheet. Any help is much appreciated. Thanks.




Code:
Sub CopySheets()


Dim c As Range


'set calc to manual to save time
    
Application.Calculation = xlCalculationManual




'copies non-rollup Sheets from hierarchy named range


For Each c In Range("hierarchy")


Sheets("Template Scorecard Sheet").Copy Before:=Sheets("Template Scorecard Sheet")
ActiveSheet.Name = c.Value


Next c


Application.Calculation = xlCalculationAutomatic


End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Solved...


Code:
Sub CopySheets()

Dim bottomA As Long, rngUniques As Range, c As Range


'set calc to manual to save time
    
Application.Calculation = xlCalculationManual


'finds unique values in Name column


bottomF = Range("F" & Rows.Count).End(xlUp).Row
Range("F1:F" & bottomF).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rngUniques = Range("F2:F" & bottomF).SpecialCells(xlCellTypeVisible)
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData




'creates a sheet for every customer


For Each c In rngUniques


Sheets("Template Scorecard Sheet").Copy Before:=Sheets("Template Scorecard Sheet")
ActiveSheet.Name = c.Value


Next c




Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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