ga7t
ga7t

Reputation: 9

Excel-VBA: Pull data from multiple closed workbooks with filename starting with "xxx"

I want to make a macro that pulls data from multiple close workbooks into this (ThisWorkbook) workbook.

All the closed workbooks are in the same folder - but there are also files that it shouldt pull data from.

So only the files starting with "0101" in the filename.

I want to copy data from A1:D18 in the first sheet of the FIRST workbook and past it into ThisWorkbook cell A1 on active sheet. And for the rest I just want to copy the C3 and put it into a variable. And if there are multiple files then it should combine all the C3-values into the same variable.

Is that possible?

Thank you so much in advance!

Upvotes: 0

Views: 2188

Answers (1)

Joel Alcedo
Joel Alcedo

Reputation: 312

This will open all Excel files starting with 0101:

Sub StringLoopOpen()

Dim folder As String
Dim file As String

folder = "C:\foo\bar"
file = Dir(folder & "\0101*.xlsx")

Do While file <> ""
Workbooks.Open Filename:=folder & "\" & file
file = Dir
Loop

End Sub

If you need to perform other tasks (such as moving the data, closing the files, etc.) do it in between "do while" and "loop".

Upvotes: 1

Related Questions