Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

consolidating contents multiple

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Consolidating contents of multiple workbooks

Consolidating contents of multiple workbooks

ResolvedVersion 2007

Rob has attended:
Excel VBA Introduction course

Consolidating contents of multiple workbooks

A common task I do is to consolidate data from multiple workbooks and I feel VBA can help reduce the amount of time it takes.

There may be approx 60 filenames and these filenames and the path are known. The biggest question is how to actually reference the multiple workbooks. I want to transfer some specific details from each sheet into a single destination sheet, adding some other properties such as the filename to each row.

RE: Consolidating contents of multiple workbooks

Hi Rob, thanks for your query. There are various ways to do this, here's one which you will need to tailor accordingly for your particular needs:

-----------------------------------

Sub GetMyData()

Dim wbOpen As Workbook
Const strPath As String = "C:\test\" '<-------change accordingly/loop through worksheet values for path
Dim strExtension As String
Dim myValue As String
Dim intTargetrowcount As Integer

intTargetrowcount = 1

Application.ScreenUpdating = False
Application.DisplayAlerts = False

ChDir strPath
'Change extension
strExtension = Dir(strPath & "*.xls")

Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension)

'Use this to check connections on first run:
'MsgBox wbOpen.Sheets("mydata").Cells(10, 4).Value

'*************************************************************
'alter the following code to tailor to your forms:

'dump the value from the returned form into a variable
'do this (with multiple variables) for multiple form results if necessary
myValue = wbOpen.Sheets("MyData").Range("d10").Value

'close down the form
wbOpen.Close SaveChanges:=False

'add the collected value to your results sheet:
Sheets("Results").Cells(intTargetrowcount, 1).Value = myValue

'and don't forget to create a new row for each returned form
intTargetrowcount = intTargetrowcount + 1

'*************************************************************

strExtension = Dir
Loop

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

-----------------------------------

Hope this helps,

Anthony

RE: Consolidating contents of multiple workbooks

Thanks for the response, this code does exactly what I needed.

Regards,
Rob

Excel tip:

Copying the same value, label or formula quickly into a range of selected cells.

Select your range of cells. Type the value, label or formula that you want to appear in all the selected cells and then press Ctrl+Enter.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.