Worksheet tab character limit

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
825
Hi

I am using the code below to rename worksheet tabs based on the value in cell B3 on each worksheet. I am getting a run time error attributed to the value in cell B3 exceeding 31 characters. This is the maximum number of characters a worksheet tab can support. Could anyone help with some additional code to rename the worksheet tabs and trim the name when 31 character limit is reached? Please note I need to keep the value in cell B3 as it is but trim the worksheet tab name only. I hope this is clear and someone can help me with this.

Code:
For I = 1 To Sheets.Count
    If Worksheets(I).Range("B3").Value <> "" Then
Sheets(I).Name = Worksheets(I).Range("B3").Value
    Else:
        Sheets(I).Name = "Default (" & I & ")"
    End If
  Next
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
825
Hi Andrew

Thanks for the quick reply. Just tested it and it works a treat. Great stuff. :)
 

precept182

New Member
Joined
Aug 6, 2013
Messages
1
How about?

Code:
Sheets(I).Name = Left(Worksheets(I).Range("B3").Value, 31)



do you know if I could limit it to a (), on my sheets I am renaming the sheets as to what is in B4 for example Heritage Foods (169000-004) how can I limit it to stop at the ( ? so that the sheet is named Heritage Foods
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,874
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
do you know if I could limit it to a (), on my sheets I am renaming the sheets as to what is in B4 for example Heritage Foods (169000-004) how can I limit it to stop at the ( ? so that the sheet is named Heritage Foods
You could use this line of code...

Code:
Sheets(I).Name = Trim(Split(Worksheets(I).Range("B4").Value, "(")(0))
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,837
Messages
5,833,918
Members
430,244
Latest member
Ireland1

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