RENAME SHEET WITH CELL VALUE UNTIL BRACKETS

xenios

Board Regular
Joined
Sep 4, 2020
Messages
91
Office Version
  1. 2016
Platform
  1. Windows
Hi, hope somebody can help me.
Need to rename workbook sheets with cell value using macros, as it's about 300 sheets.
The problem is I have for example the name TEST1 (125) MY NAME, and need the sheet to be renamed only withe text before the 1st bracket.
Is there a way to do it with macros?
 
Or do you mean you want to rename each sheet with what is in A7 on that sheet?
If so try
VBA Code:
Sub xenios2()
   Dim Ws As Worksheet
   
   For Each Ws In WorkSheets
      Ws.Name = Split(Ws.Range("A7").Value, " (")(0)
   Next Ws
End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
But that sheet already has the correct name.
Yes I send the final result, so far it was done manually. Initially all the sheets have names Sheet1, Sheet2, Sheet3/
 
Upvote 0
Or do you mean you want to rename each sheet with what is in A7 on that sheet?
If so try
VBA Code:
Sub xenios2()
   Dim Ws As Worksheet
  
   For Each Ws In WorkSheets
      Ws.Name = Split(Ws.Range("A7").Value, " (")(0)
   Next Ws
End Sub
Thank you. Tried this one.
The following error occurred (1004) attached. And the string it doesn't like is attached with debug name,
 

Attachments

  • error 1004 exl.png
    error 1004 exl.png
    8.8 KB · Views: 4
  • debug.png
    debug.png
    159.3 KB · Views: 5
Upvote 0
that sub procedure is calling the function ExtractNthWord. You need to add that. Take a screenshot of what the error is showing when the function is inserted.

Attaching you the exact string with the error.
Worksheets(I).name = ExtractNthWord(Worksheets(I).name, 1)
 

Attachments

  • extact.png
    extact.png
    174.4 KB · Views: 2
Upvote 0
Attaching you the exact string with the error.
Worksheets(I).name = ExtractNthWord(Worksheets(I).name, 1)

I have the name allways in cell A7, may be it will help.
 
Upvote 0
at what line are you getting the error at?

Error is at.
Worksheets(I).name = ExtractNthWord(Worksheets(I).name, 1)

Also all the names are in cell A7. May it may help.
 
Upvote 0
Or do you mean you want to rename each sheet with what is in A7 on that sheet?
If so try
VBA Code:
Sub xenios2()
   Dim Ws As Worksheet
 
   For Each Ws In WorkSheets
      Ws.Name = Split(Ws.Range("A7").Value, " (")(0)
   Next Ws
End Sub

Hi, I'm sorry if its wrong to ask here.
I just check this & it's okay for me, but If I have the same name on different sheets then it stops.
How to add an auto-increment number at the end for the same name?
 
Upvote 0
Hi, I'm sorry if its wrong to ask here.
I just check this & it's okay for me, but If I have the same name on different sheets then it stops.
How to add an auto-increment number at the end for the same name?
Sorry, I don't have the answer for you. But can you please send me an example of your sheet names, may be I can figure out what is wrong with mine.
Thank you.
 
Upvote 0
My names are simple name, no brackets or anything special.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
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