ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Summing two columns (https://www.excelbanter.com/excel-programming/351969-summing-two-columns.html)

Hru48[_13_]

Summing two columns
 

Hey all,

I have a worksheet which has two columns to it and I need a third t
act as a totals column for all the values in columns a and b.

I'm doing it as part of a sub in vba and I need to know if there is
short way of reffering to column as I keep ending up with pages of:

Range("G3").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
Columns("E:G").Select
Range("G4").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
Columns("E:G").Select
Range("G5").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"

Many thanks

--
Hru4
-----------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...fo&userid=2489
View this thread: http://www.excelforum.com/showthread.php?threadid=50686


Yngve

Summing two columns
 
hi hru48

try this.

Sub CountSum()
Dim colE As Double
colE = Cells(Rows.Count, "E").End(xlUp).Row
Range("G3:g" & colE).FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
End Sub
regards yngve


Bob Phillips[_6_]

Summing two columns
 
iLastrow = Cells(Rows.Count,"E").End(xlUp).Row
Range("G3").FormulaR1C1 = "=RC[-2]+RC[-1]"
Range("G3").Autofill Range("G3").Resize(iLastrow)


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Hru48" wrote in
message ...

Hey all,

I have a worksheet which has two columns to it and I need a third to
act as a totals column for all the values in columns a and b.

I'm doing it as part of a sub in vba and I need to know if there is a
short way of reffering to column as I keep ending up with pages of:

Range("G3").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
Columns("E:G").Select
Range("G4").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"
Columns("E:G").Select
Range("G5").Activate
ActiveCell.FormulaR1C1 = "=SUM(RC[-2]:RC[-1])"

Many thanks,


--
Hru48
------------------------------------------------------------------------
Hru48's Profile:

http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=506867




Hru48[_14_]

Summing two columns
 

Thanks alot for your help this is gran

--
Hru4
-----------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...fo&userid=2489
View this thread: http://www.excelforum.com/showthread.php?threadid=50686



All times are GMT +1. The time now is 11:39 AM.

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