ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SUM() cells by variables (https://www.excelbanter.com/excel-programming/388479-sum-cells-variables.html)

Dave Birley

SUM() cells by variables
 
Here's the code that it doesn't like:

myWorkCell(myCount, 17) = SUM(myWorkCell(2, 13):myWorkCell(myCount, 13))

Let's say myCount is 5, I'm expecting the cell 5 rows down and 17 to the
right to receive the value of all cells from 2 rows down and 13 to the right
to 5 rows down and 13 to the right .. in this case if myWorkCell.Row is 11,
it would present me with:

S(16) = SUM(N(12):N(16))

...at least that's what I thought I'd get. But, of course, I didn't <g!

Help, please.
--
Dave
Temping with Staffmark
in Rock Hill, SC

Norman Jones

SUM() cells by variables
 
Hi Dave,

Perhaps, try something like:

'=============
Public Sub Tester()
Dim myWorkCell As Range
Dim myCount As Long

Set myWorkCell = Range("A1")
myCount = 5

myWorkCell(myCount, 17) = _
Application.Sum(myWorkCell(2, 13).Resize(myCount))
End Sub
'<<=============


---
Regards,
Norman




"Dave Birley" wrote in message
...
Here's the code that it doesn't like:

myWorkCell(myCount, 17) = SUM(myWorkCell(2, 13):myWorkCell(myCount, 13))

Let's say myCount is 5, I'm expecting the cell 5 rows down and 17 to the
right to receive the value of all cells from 2 rows down and 13 to the
right
to 5 rows down and 13 to the right .. in this case if myWorkCell.Row is
11,
it would present me with:

S(16) = SUM(N(12):N(16))

..at least that's what I thought I'd get. But, of course, I didn't <g!

Help, please.
--
Dave
Temping with Staffmark
in Rock Hill, SC




Norman Jones

SUM() cells by variables
 
Hi Dave,

Alternatively, depending on your intended target cell, try:

'=============
Public Sub Tester()
Dim myWorkCell As Range
Dim myCount As Long

Set myWorkCell = Range("A1")
myCount = 5

myWorkCell.Offset(myCount, 17) = _
Application.Sum(myWorkCell(2, 13).Resize(myCount))
End Sub
'<<=============


---
Regards,
Norman



Dave Birley

SUM() cells by variables
 
Just what I needed!!!! Thanks.
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Norman Jones" wrote:

Hi Dave,

Perhaps, try something like:

'=============
Public Sub Tester()
Dim myWorkCell As Range
Dim myCount As Long

Set myWorkCell = Range("A1")
myCount = 5

myWorkCell(myCount, 17) = _
Application.Sum(myWorkCell(2, 13).Resize(myCount))
End Sub
'<<=============


---
Regards,
Norman




"Dave Birley" wrote in message
...
Here's the code that it doesn't like:

myWorkCell(myCount, 17) = SUM(myWorkCell(2, 13):myWorkCell(myCount, 13))

Let's say myCount is 5, I'm expecting the cell 5 rows down and 17 to the
right to receive the value of all cells from 2 rows down and 13 to the
right
to 5 rows down and 13 to the right .. in this case if myWorkCell.Row is
11,
it would present me with:

S(16) = SUM(N(12):N(16))

..at least that's what I thought I'd get. But, of course, I didn't <g!

Help, please.
--
Dave
Temping with Staffmark
in Rock Hill, SC





Dave Birley

SUM() cells by variables
 
Kewl!! I'll give that dude a shot too -- the first one worked with
qualifications -- except the qualifications had nothing to do with YOUR
contribution <g!
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Norman Jones" wrote:

Hi Dave,

Alternatively, depending on your intended target cell, try:

'=============
Public Sub Tester()
Dim myWorkCell As Range
Dim myCount As Long

Set myWorkCell = Range("A1")
myCount = 5

myWorkCell.Offset(myCount, 17) = _
Application.Sum(myWorkCell(2, 13).Resize(myCount))
End Sub
'<<=============


---
Regards,
Norman




Dave Birley

SUM() cells by variables
 
Yup, fer sure -- Version 2 was slicker 'n a pig in poop. Did the job perfectly.

Can't thank you enough! (Something about "job security" <g).
--
Dave
Temping with Staffmark
in Rock Hill, SC


"Norman Jones" wrote:

Hi Dave,

Alternatively, depending on your intended target cell, try:

'=============
Public Sub Tester()
Dim myWorkCell As Range
Dim myCount As Long

Set myWorkCell = Range("A1")
myCount = 5

myWorkCell.Offset(myCount, 17) = _
Application.Sum(myWorkCell(2, 13).Resize(myCount))
End Sub
'<<=============


---
Regards,
Norman





All times are GMT +1. The time now is 02:24 PM.

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