Copy Data from Multiple workbook into one workbook

MadhukarG

New Member
Joined
Apr 28, 2022
Messages
18
Platform
  1. Windows
  2. Web
Hi All,

I have one recurring task to copy the data from multiple excel files data received in fixed format from column C to E and from row 8 and paste the data in one master sheet one after one (data in rows can change based on business).

The multiple workbooks are saved on one path.

I want your help to draft one macro to copy the data from multiple workbooks into one workbook. (if possible Pls write text to explain as what each code performs).

Below is the data received monthly format, I need Cons Unit, Partner unit and Net book value (compile data from row 8).

Data Received.PNG


Thank you
Madhukar
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Thank you for guiding Dave - I have got below code from one thread and used it by changing the folder path and sheet name but, getting Runtime error #9 message and below code line is highligted the text in red. Dont know where I am going wrong or anything needs to be updated. I am macro learner so, cant understand much on error message.

Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Const strPath As String = "C:\Users\Madhukar.Galpalli\Downloads\PII Inventory\"
ChDir strPath
strExtension = Dir("*.xls*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("Group Inventory Input").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets("Group Inventory Input").Range("C8:E" & LastRow).Copy wkbDest.Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub
 

Attachments

  • 1658915786251.png
    1658915786251.png
    30.5 KB · Views: 10
Upvote 0
#9 could mean subscript out of range.
Do the sheet names exist or are the spelled correctly?
 
Upvote 0
Would it work if you change the sheet name from "Master" to the correct name?
The correct file name in actual scenario I will use is "Group Inventory Analysis July 2022" but, for testing the macro I was using destination file name "Master" and the destination file name suffix would change periodically with replacing Month and year at once.

The Source file names would be different based on company name etc. and within these files the data is present in sheet "Group Inventory input", I need to copy the data from all these files into one file i.e. Master file (I want to change the Master file name to "Group Inventory Analysis July 2022" while using in live environment. Only for test purpose I have changed the destination file name to "Master".

Happy to chat for quick resolution from you.
 
Last edited:
Upvote 0
The correct file name, I will use is "Group Inventory Analysis July 2022" but, this destination file (i.e. Masterfile) name suffix would change periodically with replacing Month and year at once.
And Master is not sheet name in source excel files, the sheet name is "Group Inventory Input", the master is destination file name in which I need all data from multiple files.
 
Upvote 0
isn't wkbDest the destination workbook?
Sorry, don't know what that mean to me, as I am just beginner to learn the Macro from you all experts.
For example, below is the screenshot where first four files are source files and last file "Master" is destination file but, Destination file name would be changed when macro runs successfuly.

I can change the destination file name to "Group Inventory Analysis July 2022" if that makes easy for us, but the suffix of this destination file name would change monthly like, July 2022, Aug 2022, Sep 2022 so on....

1658925006172.png
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,251
Members
453,027
Latest member
Lost_in_spreadsheets

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