naming a sheet based on the name of a cell

wolves

New Member
Joined
Dec 2, 2009
Messages
19
i have a workbook where i want to name the every sheet by the value of B1,
anyhelp?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try

Code:
Sub NameSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    With ws
        .Name = .Range("B1").Value
    End With
Next ws
End Sub
 
Upvote 0
i tried all the vba codes that i found on the net, but non of them was working, how can i attach the file so u can check it?
 
Upvote 0
You cannot attach a file here.

What happens - nothing, error, ...

What is in B1?
 
Upvote 0
nothing is happening
there is a text, even if i put any letter, it s not taking it!
i changed the name of the sheet,
it should have a specific name?
 
Upvote 0
The code that I posted works for me.

Press ALT + F11 to open the Visual Basic Editor. Select Module from the Insert menu and paste the code into the white space on the right.

Press ALT + Q to close the code window. Press ALT + F8, click on NameSheets then click the Run button.
 
Upvote 0
If you have something like dates, blanks or error values in B1, or the same value appears in B1 in more than one sheet the code will error. Try

Code:
Sub NameSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    With ws
        On Error Resume Next
        .Name = .Range("B1").Value
        On Error GoTo 0
    End With
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,314
Members
452,905
Latest member
deadwings

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