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?

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?

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

 Page 1 of 1 [ 5 post ]

Relevant Pages