Worksheet tab character limit

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
833
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

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
Hi Andrew

Thanks for the quick reply. Just tested it and it works a treat. Great stuff. :)
 
Upvote 0
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
 
Upvote 0
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))
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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