Rename sheet without Activating it

cgclower

New Member
Joined
Feb 28, 2010
Messages
40
Hello!

I am trying to write a macro to loop through all the sheets in a workbook, and if a cell is a certain value, rename the worksheet. Here is what I have so far:

For Each Sheet In ActiveWorkbook.Sheets
Sheet.Activate
If Sheet.Range("B1").Value = "Rename me" Then
ActiveSheet.Name = "NewName"
End If
Next Sheet

My question is, is there a way to accomplish this without having to activate every sheet every time?

Thanks for the help!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi

Remark:
In your code you are renaming the worksheet to the constant "NewName". This means that you can only rename 1 worksheet as you cannot have 2 worksheets with the same name.


Try:

Code:
Sub RenWks()
Dim wks As Worksheet
 
For Each wks In ActiveWorkbook.Worksheets
    With wks
        If .Range("B1").Value = "Rename me" Then wks.Name = "NewName"
    End With
Next wks
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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