Loop and Rename Worksheets

Joey_Ng

New Member
Joined
Mar 7, 2020
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to loop through a number of worksheets in the same workbook, look for the sheet names starting with sheet (eg, sheet1, sheet 2 etc...) and change those sheets with the value in cell B1 less first 4 characters. These sheets are actually "filtered pages" from a pivot table and each sheet has a value in B1. The code below only loop through the same activesheet but not actually doing anything. Help please.

Sub Loop_Rename()
Dim ws As Worksheets
Dim ct As Long, cr As String
cr = ActiveSheet.Range("B1").Value
ct = Len(ActiveSheet.Range("B1").Value) - 4
On Error Resume Next
For Each ws In ActiveWorkbook
If ws.name = "Sheet*" Then
ws.name = right(cr, ct).Value
Else
End If
Next ws
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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