Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello!
I have 5 workbooks which contain data: GROUP1.xls ... GROUP5.xls. {NOTE: These names are not cast in stone; I can change them if needed to solve this problem. Read on.} Each workbook contains 5 worksheets. The books are identical in structure, i.e. the names of the 5 worksheets are the same in all 5 workbooks, only the data on the sheets is different. I want to use a 6th workbook with VBA code to extract and combine data from the 5 workbooks (at times only two, but other times, 3, 4 or 5), but I can't figure out how to do it with a loop because I can't get the syntax correct. For example, assume cells A1 of Sheet1 of the 2,3,4 or 5 workbooks contain a number. I want Cell A1 of the 6th book to contain the sum of those numbers. So I want to loop through each of the five, add the numbers together, and display the total in Cell A1 of the 6th book. I need something which will allow me to VARY the name of the workbook I'm extracting from but still have VBA recognize it. Here is what I mean: NumberBooks = {2, 3, 4 or 5} Dim MYSHEET, SixthBook as Object Set SixthBook = {active workbook sheet} For N = 1 to NumberBooks Set MYSHEET&N = Workbooks(Group&N.xls).Sheets("SheetName") SixthBook.Cells(#,#) = Workbooks(Group&N.xls).Sheets_ ("SheetName") {addition operation} Next N {display operation} I know this isn't right, but hopefully you understand what I mean. I want to go from book to book using a for- next loop with the book name as a variable. Anybody know of a slick way to do this? Help is appreciated. OBTW: I currently have a hard-coded version of this operation which I had to complete to meet a deadline. It took 1547 lines of code. I have another project coming which will be similar, but different enough where I'll have to start from scratch. I'd like to avoid hardcoding again, hence the question. Thanks for your time. MARTY |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VB Syntax | Excel Discussion (Misc queries) | |||
VBA syntax | Excel Discussion (Misc queries) | |||
Syntax Help | Excel Worksheet Functions | |||
Help with VBA syntax | Excel Programming | |||
Syntax | Excel Programming |