Change Worksheet name to reflect Cell Value

Stephenf_07

New Member
Joined
Apr 19, 2011
Messages
8
Hello,

I would like to have Sheet 1 in my Workbook be the main sheet that controls what the rest of the Worksheets are named in the book. Whatever is entered in Cell A1 is the name of sheet 1. Whatever is entered in Cell A2 will change the name of sheet 2 and so on. Is this possible to do with VBA? I am using Excel 2010.

Thanks in advance for any help
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
something like this maybe...

Code:
Sub NameSheets()
Dim C As Range
With Sheets(1) 'Control sheet is first, yes?
 
 
    For Each C In .Range("A1:A10") '<SET p as Names Sheet of Range desired<>         
        If C.Text <> "" And C.Row <= ActiveWorkbook.Sheets.Count Then
            Sheets(C.Row).Name = Trim(C.Text)
        End If
    Next
End With
End Sub
 
Last edited:
Upvote 0
I made this a worksheet change event and put it in sheet 2 actually. This was the code I used:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim C As Range
With Sheets(2) 'Control sheet is first, yes?


For Each C In .Range("A1:A10") '<>
If C.Text <> "" And C.Row <= ActiveWorkbook.Sheets.Count Then
Sheets(C.Row).Name = Trim(C.Text)
End If
Next
End With

End Sub



I am getting an error here:
Sheets(C.Row).Name = Trim(C.Text)

What am I doing wrong? Thanks again for helping
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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