LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Need some syntax help, please

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Syntax dhstein Excel Discussion (Misc queries) 6 November 8th 08 09:13 PM
VBA syntax Sunantoro Excel Discussion (Misc queries) 1 September 21st 05 03:19 AM
Syntax Help Dmorri254 Excel Worksheet Functions 2 March 2nd 05 02:51 PM
Help with VBA syntax jacqui[_2_] Excel Programming 3 January 13th 04 02:29 PM
Syntax Michael[_23_] Excel Programming 1 December 30th 03 10:08 PM


All times are GMT +1. The time now is 01:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"