Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Summing it up | Excel Worksheet Functions | |||
Summing 2 ifs | Excel Worksheet Functions | |||
summing | Excel Worksheet Functions | |||
Summing | Excel Worksheet Functions | |||
PivotTable and summing/not summing | Excel Discussion (Misc queries) |