Check to see if sheet exists and rename it

gingerbreadgrl

New Member
Joined
Aug 19, 2019
Messages
48
Hi All,

I would like to run a macro to check to see if a sheet name exists, if it does exist, I would like to rename that sheet to be the contents of whatever is in cell B1 of that sheet. So far I have not had any luck with the using the following code, seems like it would be simple enough but I'm having trouble. Any thoughts would be much appreciated! Thanks, Gingerbreadgrl

Code:
Sub SummaryReportMacro()


Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
         If ws.Name <> "Record 2" Then
            ws.Name = ws.Range("B1").Value
        End If
    Next ws


End Sub

I've also tried:

Code:
Sub SummaryReportMacro()

Dim sht As Worksheet
For Each sht In Sheets
If sht.Name = "Record 2" Then
Sheets("Record 2") = Range("B1").Value
End If

End Sub

This didn't work either:

Code:
Sub SummaryReportMacro()

'If Sheets("Record 2").Name Then Sheets("Record 2").Name = Range(B1).Value

End Sub
 
52 is the fileformat (in this case .xlsm) I find it safer than using the format name (ie xlOpenXMLWorkbook)
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

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