Worksheet tab character limit

Jak

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

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Jak

Well-known Member
Joined
Apr 5, 2002
Messages
807
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
36,230
Office Version
2010
Platform
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))
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,681
Messages
5,512,833
Members
408,916
Latest member
juliesmithing

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top