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!
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,680
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
55,680
Office Version
  1. 365
Platform
  1. Windows
You cannot have two sheets with the same name in the same workbook.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,843
Messages
5,627,213
Members
416,230
Latest member
jdaitchman

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