Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default SumProduct with variable array

I need to calculate the sum of A1*A10 on all sheets in a workbook except for
Sheet 1 - ie Sheet2!a1*Sheet2!a10 + Sheet3!a1*Sheet3!a10 etc. I currently
have 4 sheets in the workbook + my code looks like this:

A = Array(Sheets(2).Range("a1").Value, Sheets(3).Range("a1").Value,
Sheets(4).Range("a1").Value)
B = Array(Sheets(2).Range("a10").Value, Sheets(3).Range("a10").Value,
Sheets(4).Range("a10").Value)
answer = Application.WorksheetFunction.SumProduct(A, B)

The problem is that the number of sheets in the workbook will vary over time
- how can I incorporate ActiveWorkbook.Sheets.Count or some other code to
have it calculate the answer for the current # of sheets in the workbook? Any
suggestions most welcome!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SumProduct with variable array

Dim A() as Double
Dim B() as Double
Dim i as Long
Dim answer as Double
redim A(2 to worksheets.count)
redim B(2 to worksheets.count)
for i = 2 to worksheets.count
A(i) = worksheets(i).Range("A1").Value
B(i) = worksheets(i).Range("A10").Value
Next
answer = Application.SumProduct(A,B)

--
Regards,
Tom Ogilvy


"Lynn" wrote in message
...
I need to calculate the sum of A1*A10 on all sheets in a workbook except

for
Sheet 1 - ie Sheet2!a1*Sheet2!a10 + Sheet3!a1*Sheet3!a10 etc. I currently
have 4 sheets in the workbook + my code looks like this:

A = Array(Sheets(2).Range("a1").Value, Sheets(3).Range("a1").Value,
Sheets(4).Range("a1").Value)
B = Array(Sheets(2).Range("a10").Value, Sheets(3).Range("a10").Value,
Sheets(4).Range("a10").Value)
answer = Application.WorksheetFunction.SumProduct(A, B)

The problem is that the number of sheets in the workbook will vary over

time
- how can I incorporate ActiveWorkbook.Sheets.Count or some other code to
have it calculate the answer for the current # of sheets in the workbook?

Any
suggestions most welcome!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default SumProduct with variable array

Thanks Tom - this works great!!

"Tom Ogilvy" wrote:

Dim A() as Double
Dim B() as Double
Dim i as Long
Dim answer as Double
redim A(2 to worksheets.count)
redim B(2 to worksheets.count)
for i = 2 to worksheets.count
A(i) = worksheets(i).Range("A1").Value
B(i) = worksheets(i).Range("A10").Value
Next
answer = Application.SumProduct(A,B)

--
Regards,
Tom Ogilvy


"Lynn" wrote in message
...
I need to calculate the sum of A1*A10 on all sheets in a workbook except

for
Sheet 1 - ie Sheet2!a1*Sheet2!a10 + Sheet3!a1*Sheet3!a10 etc. I currently
have 4 sheets in the workbook + my code looks like this:

A = Array(Sheets(2).Range("a1").Value, Sheets(3).Range("a1").Value,
Sheets(4).Range("a1").Value)
B = Array(Sheets(2).Range("a10").Value, Sheets(3).Range("a10").Value,
Sheets(4).Range("a10").Value)
answer = Application.WorksheetFunction.SumProduct(A, B)

The problem is that the number of sheets in the workbook will vary over

time
- how can I incorporate ActiveWorkbook.Sheets.Count or some other code to
have it calculate the answer for the current # of sheets in the workbook?

Any
suggestions most welcome!!




Reply
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
Sumproduct with a variable range rhowell100103 Excel Worksheet Functions 3 June 9th 08 03:23 AM
sumproduct - reading a variable value redneck joe Excel Discussion (Misc queries) 3 May 24th 06 08:02 PM
how can I see if an array contain a certain variable? Ronaldo[_2_] Excel Programming 3 November 17th 04 09:21 AM
about ARRAY variable Marek Excel Programming 3 September 13th 04 06:40 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 05:50 PM.

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

About Us

"It's about Microsoft Excel"