ExcelBanter

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

Kevin

Summing
 
How can I sum a range of cells in code. I have tried
myresult=Application.worksheetfunction.sum(Range(c ells
(2,1),cells(4,1))

but am having trouble. I get a syntax error.

Thanks!

Kevin

Norman Jones

Summing
 
Hi Kevin.

Sub Atester04()
Dim rng As Range
Dim myRes As Double

Set rng = Range("A2:A4")

myRes = Application.Sum(rng)
MsgBox myRes

End Sub

---
Regards,
Norman



"Kevin" wrote in message
...
How can I sum a range of cells in code. I have tried
myresult=Application.worksheetfunction.sum(Range(c ells
(2,1),cells(4,1))

but am having trouble. I get a syntax error.

Thanks!

Kevin




Kevin

Summing
 
Thanks for responding. I use the cells construct because
I am actually doing this for more than one 1 column and I
have to do it dynamically because the number of columns
needing summing is not fixed. I actually am using
variables to represent the appropriate cell coordinates.


Thanks!

Kevin
-----Original Message-----
Hi Kevin.

Sub Atester04()
Dim rng As Range
Dim myRes As Double

Set rng = Range("A2:A4")

myRes = Application.Sum(rng)
MsgBox myRes

End Sub

---
Regards,
Norman



"Kevin" wrote in

message
...
How can I sum a range of cells in code. I have tried
myresult=Application.worksheetfunction.sum(Range(c ells
(2,1),cells(4,1))

but am having trouble. I get a syntax error.

Thanks!

Kevin



.


Norman Jones

Summing
 
Hi Kevin,

Try:

Sub Atester04a()
Dim rng As Range
Dim myRes As Double
Dim i As Long, j As Long, k As Long

i = 2: j = 4: k = 1

Set rng = Range(Cells(i, k), Cells(j, k))
MsgBox rng.Address
myRes = Application.Sum(rng)
MsgBox myRes

End Sub

---
Regards,
Norman



"Kevin" wrote in message
...
Thanks for responding. I use the cells construct because
I am actually doing this for more than one 1 column and I
have to do it dynamically because the number of columns
needing summing is not fixed. I actually am using
variables to represent the appropriate cell coordinates.


Thanks!

Kevin
-----Original Message-----
Hi Kevin.

Sub Atester04()
Dim rng As Range
Dim myRes As Double

Set rng = Range("A2:A4")

myRes = Application.Sum(rng)
MsgBox myRes

End Sub

---
Regards,
Norman



"Kevin" wrote in

message
...
How can I sum a range of cells in code. I have tried
myresult=Application.worksheetfunction.sum(Range(c ells
(2,1),cells(4,1))

but am having trouble. I get a syntax error.

Thanks!

Kevin



.




Kevin

Summing
 
Thanks!
-----Original Message-----
Hi Kevin,

Try:

Sub Atester04a()
Dim rng As Range
Dim myRes As Double
Dim i As Long, j As Long, k As Long

i = 2: j = 4: k = 1

Set rng = Range(Cells(i, k), Cells(j, k))
MsgBox rng.Address
myRes = Application.Sum(rng)
MsgBox myRes

End Sub

---
Regards,
Norman



"Kevin" wrote in

message
...
Thanks for responding. I use the cells construct

because
I am actually doing this for more than one 1 column

and I
have to do it dynamically because the number of columns
needing summing is not fixed. I actually am using
variables to represent the appropriate cell

coordinates.


Thanks!

Kevin
-----Original Message-----
Hi Kevin.

Sub Atester04()
Dim rng As Range
Dim myRes As Double

Set rng = Range("A2:A4")

myRes = Application.Sum(rng)
MsgBox myRes

End Sub

---
Regards,
Norman



"Kevin" wrote in

message
.. .
How can I sum a range of cells in code. I have tried
myresult=Application.worksheetfunction.sum(Range

(cells
(2,1),cells(4,1))

but am having trouble. I get a syntax error.

Thanks!

Kevin


.



.



All times are GMT +1. The time now is 05:57 PM.

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