VBA: Creating & naming worksheets based on a template sheet

JKast

New Member
Joined
Jul 26, 2011
Messages
21
Hi all,

I'm currently using the code below to create worksheets that are formatted like the Template worksheet, and then named based on the title in each cell within the range Data1. This works prefectly as it copies the value of the name in the range to a newly created worksheet. Is there a way to copy the format of the cell too?

For example, Within my range Data1 are numbers from 1-30. The first 1-15 are colored red and 16-30 are blue. When I run the code to create worksheets 1-30, is there a way to also include the color of the cell so that worksheet tabs 1-15 would be red and 16-30 would be blue?

Public Sub MakeDestNameSheets()
Dim cell As Variant
For Each cell In Range("Data1")

Worksheets("Template").Copy after:=Worksheets(Worksheets.Count)
With ActiveSheet
.Name = cell.Value

End With

Next cell


End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Something like this:
Code:
Public Sub MakeDestNameSheets()
Dim cell As Range
    
    For Each cell In Range("Data1")
        Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
            With ActiveSheet
                .Name = cell.Value
                .Tab.ColorIndex = cell.Interior.ColorIndex
            End With
    Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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