#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default 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



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default 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


.



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Summing it up Violet 1 Excel Worksheet Functions 5 October 28th 08 08:57 PM
Summing 2 ifs Steve Excel Worksheet Functions 7 March 12th 08 03:11 PM
summing Hasty Excel Worksheet Functions 2 June 24th 07 04:31 PM
Summing Catherine Excel Worksheet Functions 4 April 26th 07 06:44 PM
PivotTable and summing/not summing ~*Amanda*~[_2_] Excel Discussion (Misc queries) 1 March 14th 07 07:35 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"