Macro to change multiple files Sheet name

Raychin

New Member
Joined
Apr 7, 2022
Messages
25
Office Version
  1. 2013
Platform
  1. Windows
Hi there! I need a macro to change the name of the sheet of multiple .xls files in a folder. The sheets in the files are named like date and i need them be changed to Sheet (1) so after that standartisation i can run a macro to copy the numbers from B2:B25 to a specific Master file column. I tried several VBA codes but non of them working properly. The files sheet names is like this : IDM Result for 2021-01-03 to be change to Sheet1. I attached two images of what is the name of the sheet from files i need to be changed and place (column) where should be B2:B25 data should go afterwards.
Thank you in advance!
 

Attachments

  • Place to paste the data.JPG
    Place to paste the data.JPG
    73.9 KB · Views: 10
  • Sheet name to change.JPG
    Sheet name to change.JPG
    75.3 KB · Views: 8
I actually manage to do the job with this code since i don't have to change names :

Sub ImportFiles()

Dim wbNew As Workbook, strPath As String, xWS As Worksheet, xMWS As Worksheet, xTWB As Workbook
Dim xStrAWBName As String, Sh1 As Worksheet, FolderName As String, R As Long, Lr1 As Long
Dim FolderPath As String, fldr As FileDialog, sItem As String, FileName As String, Lr2 As Long
Dim LC As Long
On Error Resume Next
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
FolderName = sItem
Set fldr = Nothing
FolderPath = FolderName & "\"

Set xTWB = ThisWorkbook
Set Sh1 = xTWB.Sheets("Data Collector")
FileName = Dir(FolderPath & "*.xls*")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Do While FileName <> ""
Workbooks.Open FileName:=FolderPath & FileName, ReadOnly:=True
xStrAWBName = ActiveWorkbook.Name
For Each xWS In ActiveWorkbook.Sheets
Lr1 = xWS.Range("A" & Rows.Count).End(xlUp).Row
R = Application.WorksheetFunction.CountA(xWS.Range("A1:A" & Lr1))
If R > 0 Then
Lr2 = Sh1.Range("A" & Rows.Count).End(xlUp).Row + 1
xWS.Range("A1:A" & Lr1).Copy Sh1.Range("A" & Lr2)
End If
Next xWS
Workbooks(xStrAWBName).Close
FileName = Dir()
Loop
xTWB.SaveAs FileName:="C:\Users\kuser\Desktop\Energy Storage", FileFormat:=xlWorkbookNormal
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic

End Sub
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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