VB Code to rename sheet

backfromthebush

New Member
Joined
Jul 2, 2010
Messages
37
Hi,
Im having a problem with my code in trying to rename a new sheet.

The first sheet is named "Data", and in column B I have a list of names which I eventually want each one to have a new sheet named after.

Lets say B1 has the name "Apples", I need the code to create a new tab called "Apples", then go to cell B2, which will have "Bananas", and create a new tab called "Bananas", etc, until it reaches a cell with no data, where it will exit the procedure.

Can anyone please help!! :)
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Blade Hunter

Well-known Member
Joined
Mar 13, 2008
Messages
3,147
Dump the list to an array
Poll the array and for each entry that is not blank, create a new sheet and name accordingly

Code:
Sub NewSheetsFromList()
Dim MyList() As Variant
Dim MyVal As String
MyList = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
For Each MyVal In MyList
    If MyVal <> "" Then
        Worksheets.Add
        ActiveSheet.Name = MyVal
    End If
Next
Sheets("Data").select
End Sub
 
Upvote 0

Dryver14

Well-known Member
Joined
Mar 22, 2010
Messages
2,396
Blade,

If the list is alphabetical is it not worth using

Worksheets.Add after:=Worksheets(Worksheets.Count)

Or does your method follow on anyway?
 
Upvote 0

Blade Hunter

Well-known Member
Joined
Mar 13, 2008
Messages
3,147
It just adds them to the start in the order they were listed. (Which will effectively reverse the list. Making the change you suggest would be a good idea to maintain structure.
 
Upvote 0

Forum statistics

Threads
1,191,538
Messages
5,987,172
Members
440,083
Latest member
Bluepanther

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
Top