Seeking method to name a worksheet, limited to 31 characters

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
734
Office Version
  1. 365
Platform
  1. Windows
I have this small bit of code which is part of a much larger project. It simply re-names each worksheet to the value of cell B1 on that sheet.

Code:
    For Each ws In ActiveWorkbook.Worksheets
        ws.Name = Range("B1").Value
    Next ws

Today, I came across a value in cell B1 that is 32 characters. Sheet names are limited to a maximum of 31 characters.

What can I add to this code? I'd like to use only the first 31 characters in cell B1 as the new sheet name. I can't change the value in cell B1, this needs to be part of the code.

Thanks in advance.

Jim
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Just use the LEFT function to take the first 31 characters, i.e.
Code:
ws.Name = Left(Range("B1"),31)
 
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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