Rename tabs as cell A2, for every sheet

sweeneytime

Board Regular
Joined
Aug 23, 2010
Messages
183
Hi guys,

I have the below code,renaming each tab as A2 & "Transactions" but on sheet 2 it is still trying to use cell A2 from the sheet 1, I need to pick up A2 from each sheet while active, any suggestions please?

Also do you know how I can start from just the second sheet please?

Thanks,
Alan

Code:
Sub Rep()
    
    Dim ProjName As String

     For Each sht In ThisWorkbook.Worksheets
            
            sht.Name = Range("A2") & " Transactions"
     Next sht

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You need to reference the sheet in the code.
simply doing a for each sht loop doesn't make each sheet active during the loop.
And VBA doesn't assume you want to reference the sht in the loop.
Unless otherwise specified, VBA still references whichever sheet is currently active.

sht.Name = sht.Range("A2") & " Transactions"
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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