Rename Worksheet with Delimited Workbook name

Poppaby

New Member
Joined
Nov 19, 2020
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
Hi All

I have a folder with a number of workbooks. Each file has 1 tab called "sheet 1".

Each workbook has a long complex name in the form of xxxxx_xxx_xxxx_xxxxxx_y_xxxxxxxx_x

where the x is a set length on every workbook, but the y is a random length in each file

I would like to rename "sheet 1" in every workbook in a set folder to "y"

Is there a way to use the "_" delimiter to create a macros for this purpose?

Additionally, is there a way to then expand on this result to further amend the name - like a recurring if function so that

if "y" = Apples then rename the worksheet RED_Apples

Thanks in advance for any help you can provide

Dave
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Ok, how about
VBA Code:
Sub Poppaby()
   Dim Pth As String, Fname As String
   Dim Sp As Variant
   Dim Wbk As Workbook
   
   Pth = "C:\MrExcel\Fluff\"
   Fname = Dir(Pth & "*.xls*")
   Do While Fname <> ""
      Set Wbk = Workbooks.Open(Pth & Fname)
      Sp = Split(Fname, "_")
      Wbk.Sheets(1).Name = Sp(4)
      Wbk.Close True
      Fname = Dir
   Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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