loop changing sheet names based on cell value

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I've found how to change a sheet name based on a cell value.
VBA Code:
Sheets("Sheet1").name = Range("A1").Value
I would like to add this to a loop I have. Can it even be done?
This is what I came up with, epic fail!
VBA Code:
Dim Sht as Variant
    For Each Sht In Array("Sheet1", "Sheet2", "Sheet3")
        With Sheets(Sht)
        .Sheets.Name = .Range("A2").Value
        End With
    Next
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
The fact that you want to do this in a loop suggests that you want to rename multiple worksheets. Is that correct?
 
Upvote 0
The fact that you want to do this in a loop suggests that you want to rename multiple worksheets. Is that correct?
Yes, that is correct. I'm looking to change Sheet1, Sheet2, and Sheet3 to the value in A2 on either of their respective sheets.
 
Upvote 0
then you were pretty close...

VBA Code:
Dim Sht as Variant
    For Each Sht In Array("Sheet1", "Sheet2", "Sheet3")
        With Sheets(Sht)
            .Name = .Range("A2").Value
        End With
    Next
 
Upvote 0
Solution
then you were pretty close...

VBA Code:
Dim Sht as Variant
    For Each Sht In Array("Sheet1", "Sheet2", "Sheet3")
        With Sheets(Sht)
            .Name = .Range("A2").Value
        End With
    Next
I was so close. So I can speak more intelligently, what is ".Name" called? I would like to know more about the different <insert name here> that can be used with a "With" statement. I would like to start with the basics.
Ones I know from other questions I posted are -
.Range
.Columns
.Rows

Thank you!
 
Upvote 0
Well, the VBA Editor (VBE) can help you with that. The Object Browser (F2 key) is a nice tool, and taking advantage of Intellisense may also be a great help.
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

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