Merging excel files to form a master data

Raghavan Sundaram

New Member
Joined
Jul 24, 2020
Messages
2
Office Version
  1. 2013
  2. 2010
  3. 2007
Platform
  1. Windows
Hello All,

I found this macro on the internet that allows me to combine multiple excel reports stored in a folder under one workbook. However, when I use this code now I get a run time error. I am new to macro and would appreciate if someone can help me solve this error. The code that I use below and the line that shows as an error shown in a different font color.


Sub FindExcelFiles()
Dim FileName As String
Dim FolderPath As String
Dim wb As Workbook
FolderPath = "\\CNHKGFS001\users\rsundaram\My Documents\Raghavan\ALL FILES\Customers\RFQ's\Philippines\Kaercher\Inventory 2019-2020\Inventory Reports\"
FileName = Dir(FolderPath & "*.xls")
Do While FileName <> ""
Set wb = Workbooks.Open(FolderPath & FileName)
wb.Sheets(1).Copy after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count).Name = Left(Left(FileName, InStrRev(FileName, ".")), 32)
FileName = Dir()
wb.Close SaveChanges:=False
Loop
End Sub

Thanks!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,540
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
A sheet name cannot be more than 31 characters in length, so change the 32 to 31
 

Raghavan Sundaram

New Member
Joined
Jul 24, 2020
Messages
2
Office Version
  1. 2013
  2. 2010
  3. 2007
Platform
  1. Windows
Hello Fluff,

I still get the below error.

1595828968080.png
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,540
Office Version
  1. 365
Platform
  1. Windows
You cannot have two sheets with the same name in the same workbook.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,531
Messages
5,854,284
Members
431,636
Latest member
shabbas313

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
Top