PDA

View Full Version : Use a master list to run a macro that opens, extracts, and closes multiple workbooks



Commoner
10-10-2020, 03:00 PM
I have a master workbook with a list of about 100 items and most of the items also have their own workbook with the name of the item as the name of the workbook. Within each workbook there is a worksheet that has data and I want so extract just a portion of the data into a single sheet in the master workbook. Is there a way to do this with VBA code where it loops through each workbook one at a time by finding the workbook based on the item name in the list and then extract data then close the workbook?

snb
10-11-2020, 04:14 AM
If you store the data of the 100 items in 1 worksheet (and there's enough space to do so) your 'problem' doesn't even arise.
'Structuring precedes coding'.

Commoner
10-11-2020, 04:33 AM
If you store the data of the 100 items in 1 worksheet (and there's enough space to do so)

That is actually the goal. How do I automate that from the 100 workbooks? Each item has 60 data points. I need to get 10 of those data points from each of the workbooks into a master sheet.

The reason I have about 100 workbooks is because I had to pull the data into each of the workbooks with a specific program that didn't give me an option to make one large worksheet of the 100 items into a single workbook.

snb
10-11-2020, 04:40 AM
Sub M_snb()
sn=sheet1.range("A1:A100")

for each it in sn
sheets.add(,sheets(sheets.count),,"G:\OF\" & it & ".xlsx"
next
End Sub

Why do you provide too little information to answer your question adequately?

Commoner
10-11-2020, 05:20 AM
Why do you provide too little information to answer your question adequately?

I thought I had provided enough information. That means I don't have enough knowledge to know what you need to know and I don't know what isn't understood, yet stated, in my posts. I don't need to add sheets. I want to avoid getting 100 sheets into a single workbook. I thought opening a workbook with VBA uses Workbooks.Open

Rewording my situation -
I have about 100 workbooks. All closed. Need to use VBA to open each workbook and extract 10 data points from a single sheet in each workbook into a master sheet in a master workbook that has a list of about 100 items in a single column. Each of the about 100 workbooks has the name of the item as the name of the workbook. The data points are in column B in the individual workbooks with the "header" in A. I need to get the data points into rows in the master sheet, corresponding to the item name, and the header will be in a row at the top of the master sheet.

Is there a way to create a macro with VBA to do that?