Consolidate data from 10 different workbooks

KJones97

New Member
Joined
Jul 2, 2019
Messages
9
Greetings,

I need help building a macro that gathers information from 1 workbook with a variable name and consolidating it into a tab on a different workbook.

For the source file the data I need is in cells (O11, O13, O17:O20, P11, P13, P17:20) on the first sheet titled "Valuation Detail". As for the workbook name, however, I will be creating new workbooks on a monthly basis, so I would preferably need the macro to work without me having to go in every month and change the file path. The file will always be named first by the date (formatted yymmdd) followed by " HC896 Template Output".

This data needs to be copied to a workbook titled Destination.xls within the same file folder to the sheet titled "HC896" in the same order to cells (D8, D10, D14:17, E8, E10, E14:E17) Ex. O11 -> D8, O13 -> D10, O17:O20 -> D14:D17.

I am hoping to be able to input the date desired for the data pull into cell J2 within the Destination.xls workboo "HC896" tab and have the macro find the proper file.

The file path where the files are located is: "F:\Desktop\BONDS" where I will place the new data each month and update the date before the file name " HC896 Template Output" (yymmdd)

I hope this is enough hypothetical information to enable you all to help me with the code.

Thank you all very much in advance.

Regards,

KJones
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the forum.

Open a copy of your Destination.xls workbook. Press Alt-F11 to open the VBA editor. Press Alt-IM to create a module. Paste this code into the module:

Code:
Sub GetData()
    Application.ScreenUpdating = False
    Workbooks.Open Filename:="F:\Desktop\BONDS\" & Range("J2").Value & " HC896 Template Output.xlsx"
    Range("O11:P11").Copy ThisWorkbook.ActiveSheet.Range("D8:E8")
    Range("O13:P13").Copy ThisWorkbook.ActiveSheet.Range("D10:E10")
    Range("O17:P20").Copy ThisWorkbook.ActiveSheet.Range("D14:E17")
    ActiveWorkbook.Close
    Application.ScreenUpdating = True
End Sub
Press Alt-Q to close the editor. You will have to save this workbook as a macro-enabled workbook. Go to your HC896 sheet, enter the date in J2, and press Alt-F8. Select GetData and press Run.

That should do it. There's no error checking in the macro, which we can add later, but it should work. We can add a button to execute the macro too, either on the sheet or the Ribbon. Let us know.
 
Upvote 0
Hi Eric,

Thank you so much for the help and the fast reply.


The excel runs with no errors and with the data source file open the macro closes the file so I know that is working properly. However, No data gets posted to the HC896 sheet.

KJones97
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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