VBA: Extract data from multiple spreadsheets

Melanie

Board Regular
Joined
Sep 17, 2003
Messages
51
I have several spreadsheets that are formatted exactly the same and I want to extract data located in the same place on each spreadsheet. Is there a way in vba to accomplish this? I do have the names of each spreadsheet on a separate spreadsheet.

I essentially want to loop through the spreadsheet names, open up each spreadsheet, extract the data and paste it in a table format.

Thanks in advance.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The following statement in a VBA macro with your values substituted for the "This" and "That" items below will copy from 1 book to another:

Workbooks(ThisBook).Sheets(ThisSheet).cells(ThisRow,ThisColumn).value = Workbooks(ThatBook).Sheets(ThatSheet).cells(ThatRow,ThatColumn).value
 
Upvote 0
I will definitely try that.

Do you know how to loop through the spreadsheet names I have listed on the spreadsheet?
 
Upvote 0
I just realized that you are referring to spreadsheets and not workbooks. Do you mean extracting data from several sheets within the same workbook or from several different workbooks?
 
Upvote 0
I meant extracting from several different workbooks.

For example, if I have the following workbook names listed in cells A1, A2, and A3 of a spreadsheet.

A.xls
B.xls
C.xls

I want to loop through the three cells and open up each workbook using the name contained within each cell. Then I need to copy a range from each workbook and paste it into a common spreadsheet.
 
Upvote 0
Here is my suggestion; others may prefer a different method:

Above the workbooks: Have a cell where you enter the folder name where the workbooks have to be read from, assuming they are all in the same folder (?)

Give that cell a range name of "FolderName".

Also above the workbooks - have a "header row" where you type something like "List of Workbooks". Name that cell "WkbksHeader".
Beneath the list of workbooks have a "footer row" where you type "End of List". Name that cell "WkbksEnd".

Your loop can be a For/Next: For NextBook = (Range("WkbksHeader").row + 1) to (Range("WkbksEnd").row - 1)

Each time through the loop, you get the next workbook name, append it to the foldername, which you read prior to the loop, and open the workbook. Do your cell copies and then close the workbook.

Hope this gets you started.
:)
 
Upvote 0

Forum statistics

Threads
1,214,377
Messages
6,119,185
Members
448,872
Latest member
lcaw

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