Macro to rename sheets

nhayden73

New Member
Joined
Jan 10, 2018
Messages
8
Hi all,

I using a simple VB code that takes the name from a specific sheet cell and changes the tab name to match when that tab is activated.
I want to expand on this macro to have a message pop-up if there is an error with the name structure. Like having the same name as another tab or if the name violates the characters that can be use.

Here is the code that I have so far. (borrowed from a google search)

Private Sub Worksheet_Activate()
newname = Range("C6").Text
On Error Resume Next
If Right(newname, 1) = " " Then newname = Left(newname, (Len(newname) - 1))
ActiveSheet.Name = newname
End Sub

I am not sure how to add in a simple message in case there is an error.
Something like: "Please Revise Room Name. It appears to contain an illegal character."

I have tried using the code from this post. https://excel.tips.net/T002145_Dynamic_Worksheet_Tab_Names.html
The problem I encounter with this code is that when using the "FIND" or "REPLACE" features on the workbook level it triggers a Debug error.

Any assistance would be greatly appreciated.
 
Glad we could help & thanks for the feedback
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,216,084
Messages
6,128,730
Members
449,465
Latest member
TAKLAM

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