PDA

View Full Version : Solved: SUM Formula



Giri
07-10-2011, 03:21 AM
Hi Guys,

Could someone please let me know how to write the formula to SUM two ranges when the two ranges have been defined as variables of type range?

E.g

Dim rangeOne as Range
Dim rangeTwo as Range

Set rangeOne = Range("A1")
Set rangeTwo = Range("A5")


So if I wanted to use "rangeOne" and "rangeTwo" in the SUM formula, how would that be written?


Range("B1").Formula = ????


Thank you!

Kind Regards,

Giri

Bob Phillips
07-10-2011, 03:40 AM
Range("B1").Formula = "=" & rangeone.address & "+" & rangetwo.address

Giri
07-10-2011, 03:48 AM
Oops Sorry... should have been more clear.

I meant, summing "A1:A5".

Thanks xld.

Kind Regards,

Giri

Aussiebear
07-10-2011, 04:07 AM
Range ("B1").Formula = "=Sum" & Range0ne.Address & "+" & Rangetwo.Address

Giri
07-10-2011, 05:08 AM
Thanks Aussie Bear.

For some reason I am getting "Run Time Error 1004: Application Defined Error"

This is the code I have. I'm not sure what I am doing wrong because all the variables seem to be referenced correctly.


Giri.Offset(-2, 0).Formula = "=SUM" & topRed.Address & "+" & redEnd.Address


Any ideas what RunTime Error 1004 refers to?

Thanks.

Kind Regards,

Giri

Bob Phillips
07-10-2011, 07:23 AM
Dim rangeOne As Range
Dim rangeTwo As Range

Set rangeOne = Range("A1")
Set rangeTwo = Range("A5")

Range("B1").Formula = "=SUM(" & Range(rangeOne, rangeTwo).Address & ")"

Giri
07-10-2011, 02:37 PM
Perfect, xld!

Thank you!

Kind Regards,

Giri