excel
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel

Excel

resolvedResolved · Medium Priority · Version 2007

replyReply Tue 14 Oct 2008, 16:44Delegate Hiral said...

Hiral has attended:
Excel VBA Intro Intermediate course

Excel

How to consolidate data of various worksheets from different workbooks into one worksheet ?

For upcoming training course dates see: Pricing & availability

replyReply Wed 15 Oct 2008, 11:40Trainer Roy said...

RE: Excel data consolidation

Hiral,
We looked at this with the last example of the course: merging data from various source workbooks (Centre1, Centre2, ...) into a single workbook (Consolidated).

The example relies on all the source workbooks having names that can be constructed as "Centre" & i, for i = 1, 2, ..., inside a loop. The body of the loop is:

source_wbname = "Centre " & i & ".xls"
Workbooks.Open (source_wbname) 'Becomes active

ActiveWorkbook.Worksheets("Marks").Copy _
after:=Workbooks(destination_wbname).Worksheets(wscount)

Workbooks(source_wbname).Close 'This workbook becomes active

ActiveWorkbook.Worksheets("Marks").Name = "Centre " & i

wscount = wscount + 1
i = i + 1

We used the file-not-found error to jump out of the loop - again, see the notes.

Note that when using multiple workbooks, life is simpler if they are all in the same folder on disk.

Hope this helps,
/Roy MacLean

 

Please browse our web site to find out more about
vba-excel-training and other Microsoft training courses.

Excel tip:

Moving or Copying Sheets Between Workbooks in Excel 2010

Here's how to move or copy sheets between workbooks in Excel 2010:

Open the sheet you want to move or copy then on the Ribbon click the Home tab. Click Format. Under Organize Sheets, select the option Move or Copy Sheet and then choose where you want the sheet to be moved/copied to.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard