SUM from a table in a variable 
Author Message
 SUM from a table in a variable

Hello all,

I want to get the sum of some cells from a table into a variable. It
shuld look something like this:

myVariable = SUM(A1:A10)

Could anyone of you help me?
Thanks in advance....



Fri, 02 Dec 2005 15:48:05 GMT  
 SUM from a table in a variable
Hi Pt,

Use:

Dim mysum, i
mysum = 0
For i = 1 To 10
    mysum = mysum + Val(ActiveDocument.Tables(1).Cell(i, 1).Range)
Next i
MsgBox mysum

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:
> Hello all,

> I want to get the sum of some cells from a table into a variable. It
> shuld look something like this:

> myVariable = SUM(A1:A10)

> Could anyone of you help me?
> Thanks in advance....



Fri, 02 Dec 2005 17:14:37 GMT  
 SUM from a table in a variable
Hello,

Thanks for your help. Yes, that worked to sum the contents.

But 'Val' gets only the numeric value. That means in those columns i
have an amount, like 10'000.00. But with 'Val' i get only 10. How
could I sum it up and to get the sum in a currency value?

regards, PT



Fri, 02 Dec 2005 20:39:38 GMT  
 SUM from a table in a variable
Hi PT,

Use the following then:

Dim mysum, i, myrange As Range
mysum = 0
For i = 1 To 10
    Set myrange = ActiveDocument.Tables(1).Cell(i, 1).Range
    myrange.End = myrange.End - 1
    If IsNumeric(myrange) Then mysum = mysum + myrange
Next i
MsgBox mysum

--
Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP

Quote:
> Hello,

> Thanks for your help. Yes, that worked to sum the contents.

> But 'Val' gets only the numeric value. That means in those columns i
> have an amount, like 10'000.00. But with 'Val' i get only 10. How
> could I sum it up and to get the sum in a currency value?

> regards, PT



Fri, 02 Dec 2005 21:59:15 GMT  
 SUM from a table in a variable
Hello,
It worked. I thank u again for your help :-)
regards


Sat, 03 Dec 2005 15:40:12 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. help: Crystal Reports with Variables and Sums

2. Add or Sum variable in ASP

3. table join with a sum works in sql

4. doing sums in a table outlook view

5. calculating sums in a table formated view !

6. Need help with joined table sum query

7. Summing a table

8. ~Sum existing values with values from another table

9. Updating using Sums from another Table.

10. ~Sum existing values with values from another table

11. AM I missing something - Sum and Cumulative Sum

12. Report showing BOTH Aggregate Sum of Display records and Total Sum by Group

 

 
Powered by phpBB® Forum Software