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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,​
as your procedure seems to search a worksheet name that can not exist (‼) so what is the actual real name of the worksheet ?​
 
Upvote 0
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."
 
Upvote 0
So you just need to test the sheet name like If ws.Name = "Totals - MM.DD.YYYY" Then ws.Name = "Totals - " & ws.[B11].Text
 
Upvote 0

Forum statistics

Threads
1,212,934
Messages
6,110,762
Members
448,295
Latest member
Uzair Tahir Khan

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