ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sum a range with vba (https://www.excelbanter.com/excel-programming/334962-sum-range-vba.html)

jhahes[_18_]

Sum a range with vba
 

How do I do the following

I want to sum the following range


This is my guess, but it didn't work

Dim x as currency

x = Sum(Range("OutstandingBalance"))

MsgBox x


Thanks for any help

Jos

--
jhahe
-----------------------------------------------------------------------
jhahes's Profile: http://www.excelforum.com/member.php...fo&userid=2359
View this thread: http://www.excelforum.com/showthread.php?threadid=38844


Trevor Shuttleworth

Sum a range with vba
 
Josh

try:

Dim x As Currency
x = WorksheetFunction.Sum(Range("OutstandingBalance"))
MsgBox x

Regards

Trevor


"jhahes" wrote in
message ...

How do I do the following

I want to sum the following range


This is my guess, but it didn't work

Dim x as currency

x = Sum(Range("OutstandingBalance"))

MsgBox x


Thanks for any help

Josh


--
jhahes
------------------------------------------------------------------------
jhahes's Profile:
http://www.excelforum.com/member.php...o&userid=23596
View this thread: http://www.excelforum.com/showthread...hreadid=388442




Max

Sum a range with vba
 
I assume you want the simplest method in which case you already have your
answer. Another approach would be to do a For...Each Cell in your range and
then maintain a running total of each of the Cell.Values. I guess this
method is oly useful if there is anything else you want to do with the
numbers as well as simply SUM them.

Cheers, Max

"jhahes" wrote:


How do I do the following

I want to sum the following range


This is my guess, but it didn't work

Dim x as currency

x = Sum(Range("OutstandingBalance"))

MsgBox x


Thanks for any help

Josh


--
jhahes
------------------------------------------------------------------------
jhahes's Profile: http://www.excelforum.com/member.php...o&userid=23596
View this thread: http://www.excelforum.com/showthread...hreadid=388442



jhahes[_19_]

Sum a range with vba
 

I tried the code and got a debug error as follows


Method Range of Object Worksheet Failed


Thanks

Josh


--
jhahes
------------------------------------------------------------------------
jhahes's Profile: http://www.excelforum.com/member.php...o&userid=23596
View this thread: http://www.excelforum.com/showthread...hreadid=388442


Losse[_35_]

Sum a range with vba
 

Trevor's code should work...are you sure you have defined the range an
are on the correct sheet

--
Loss
-----------------------------------------------------------------------
Losse's Profile: http://www.excelforum.com/member.php...fo&userid=2481
View this thread: http://www.excelforum.com/showthread.php?threadid=38844


Trevor Shuttleworth

Sum a range with vba
 
Losse

not much to go wrong really ;-)

The sheet shouldn't matter as the range is defined. If the range name isn't
defined (a typo maybe), I get a slightly different error message:

Method 'Range' of object '_Global' failed

Perhaps it depends on the version of Excel ?

Regards

Trevor


"Losse" wrote in
message ...

Trevor's code should work...are you sure you have defined the range and
are on the correct sheet?


--
Losse
------------------------------------------------------------------------
Losse's Profile:
http://www.excelforum.com/member.php...o&userid=24813
View this thread: http://www.excelforum.com/showthread...hreadid=388442





All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com