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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi & welcome to MrExcel.
A sheet name cannot be more than 31 characters in length, so change the 32 to 31
 
Upvote 0
Hello Fluff,

I still get the below error.

1595828968080.png
 
Upvote 0
You cannot have two sheets with the same name in the same workbook.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,755
Members
449,049
Latest member
excelknuckles

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