Renaming multiple tabs from cell - how to limit to 30 characters?

Gerald Crumbley

New Member
Joined
Oct 6, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I have a monthly report to produce, I have 51 .xlsx sheets to combine. I have found how to import all into different worksheets. I have found how to rename each worksheet to a cell value.

Problem: the tabs can only be 31 characters or less, or the script doesn't rename it.
Question: How can I cut the cell characters to 30 before running the rename script?

Below is my Tab Rename script. If I can add to this to cut the cells to 30, great. If I need to create a new macro, please let me know. Thanks for any advice or direction:

Sub RenameTabs()
Dim ws As Worksheet
For Each ws In Worksheets
On Error Resume Next
If Len(ws.Range("F5")) > 0 Then
ws.Name = ws.Range("F5").Value
End If
On Error GoTo 0
Next
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the Board!

Maybe change this:
VBA Code:
ws.Name = ws.Range("F5").Value
to this:
VBA Code:
ws.Name = LEFT(ws.Range("F5").Value,30)
 
Upvote 0
Solution
Welcome to the Board!

Maybe change this:
VBA Code:
ws.Name = ws.Range("F5").Value
to this:
VBA Code:
ws.Name = LEFT(ws.Range("F5").Value,30)
OMG! I have worked hours on this! I tried that but I was putting it on a separate line. You are wonderful! Thank you!
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0
Hi Joe4,
how do skip first and second tab? start rename only on third tab?
You can do that like this:
VBA Code:
Sub RenameTabs()

    Dim i As Long
    Dim ws As Worksheet

    For i = 3 To Sheets.Count
        Set ws = Sheets(i)
        On Error Resume Next
        If Len(ws.Range("F5")) > 0 Then
            ws.Name = Left(ws.Range("F5").Value, 30)
        End If
        On Error GoTo 0
    Next i

End Sub
 
Upvote 0
You can do that like this:
VBA Code:
Sub RenameTabs()

    Dim i As Long
    Dim ws As Worksheet

    For i = 3 To Sheets.Count
        Set ws = Sheets(i)
        On Error Resume Next
        If Len(ws.Range("F5")) > 0 Then
            ws.Name = Left(ws.Range("F5").Value, 30)
        End If
        On Error GoTo 0
    Next i

End Sub
Hi Joe4,

Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,223,637
Messages
6,173,488
Members
452,515
Latest member
archcalx

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