How to Rename 2 sheets with concatenated text based on cells

Jiriyanu

New Member
Joined
Dec 11, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

What I am trying to do is rename two sheets. Both start off with specific names with identical dates in the sheet name as they need to be saved separately for upload.

So for sheet A, I'm wanting to locate the sheet that contains text "Totals - MM.DD.YYY" then rename by concatenating "Totals -" and a new date based on a cell in Sheet A.
For sheet B, I need to do basically the same thing except with different text, still using the date in Sheet A.

This is what I have so far.

VBA Code:
Sub Rename()
    ' To set dynamic worksheet names
    Application.ScreenUpdating = False
    Dim ws As Worksheet

    For Each ws In Worksheets
        If ws.Name = "Totals - MM.DD.YYYY" Then
            ws.Name = ws.Range("B11").Value
        esle
            ws.Name = ws.Range("B11").Value
        End If
    Next
    Application.ScreenUpdating = True

End Sub

I'm not really sure how to search for a sheet containing certain text, or concatenate when renaming the sheet. If you could help me out, I would really appreciate it. Thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,293
Office Version
  1. 2010
Platform
  1. Windows
Hi,​
as your procedure seems to search a worksheet name that can not exist (‼) so what is the actual real name of the worksheet ?​
 

Jiriyanu

New Member
Joined
Dec 11, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi,​
as your procedure seems to search a worksheet name that can not exist (‼) so what is the actual real name of the worksheet ?​
Sheet A is named as "Totals - MM.DD.YYYY."
Sheet B is named as "12345-01MMDDYYYY."
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,293
Office Version
  1. 2010
Platform
  1. Windows
So you just need to test the sheet name like If ws.Name = "Totals - MM.DD.YYYY" Then ws.Name = "Totals - " & ws.[B11].Text
 

Forum statistics

Threads
1,141,816
Messages
5,708,752
Members
421,588
Latest member
Wawie

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
Top