Get data from multiple sheets in multiple workbooks into master workbook with vba

mychi11

Board Regular
Joined
May 11, 2020
Messages
95
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I am trying to transfer several rows (there isnt specific number of rows) from column J from several worksheet saved in my C drive in a folder named "inventory" into my master sheet. I have little knowledge in vba. I have the following code. However, I am getting error 13 and mismatch error when I am trying to run code. I am wondering if any of you can kindly help? many thanks in advance.

Sub copyDataFromMultipleWorkbooksIntoMaster()

Dim FolderPath As String, Filepath As String, Filename As String

FolderPath = "C:\Inventory\"

Filepath = FolderPath & "*.xls*"

Filename = Dir(Filepath)

Dim lastrow As Long, lastcolumn As Long

Do While Filename <> “”
Workbooks.Open (FolderPath & Filename)

lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close

erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination = Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow, 10))


Filename = Dir

Loop
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Sorry i realised i have a bit a typo in my message.
**
I am trying to transfer several rows (there isnt specific number of rows) from several worksheet saved in my C drive in a folder named "inventory" into my master sheet without having the need to open those worksheet. I have little knowledge in vba. I have the following code. However, I am getting error 13 and mismatch error when I am trying to run code. I am wondering if any of you can kindly help? many thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,215,826
Messages
6,127,117
Members
449,359
Latest member
michael2

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