ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with cell reference (https://www.excelbanter.com/excel-programming/356194-help-cell-reference.html)

Harjinder Singh

Help with cell reference
 


Hi,

I am trying to sum of few cell wherein i am not sure what would be the
maximum cell.

for example if i am using the below given formula it givs me the some of
cell one to cell four but i do not want the static result.
"=SUM(RC[1]:RC[4])"

will it possible if I assign a value to a variable:

like

a=20
and use the formula like this:

"=SUM(RC[1]:RC[a])"

- Harry

*** Sent via Developersdex http://www.developersdex.com ***

Ardus Petus

Help with cell reference
 
Sub test()
Dim a As Long
Dim isum As Double
a = 20
isum = Application.WorksheetFunction.sum(Range( _
Cells(1, "A"), _
Cells(a, "A") _
))
MsgBox isum
End Sub

HTH
--
AP

"Harjinder Singh" a écrit dans le message de
...


Hi,

I am trying to sum of few cell wherein i am not sure what would be the
maximum cell.

for example if i am using the below given formula it givs me the some of
cell one to cell four but i do not want the static result.
"=SUM(RC[1]:RC[4])"

will it possible if I assign a value to a variable:

like

a=20
and use the formula like this:

"=SUM(RC[1]:RC[a])"

- Harry

*** Sent via Developersdex http://www.developersdex.com ***




kwiklearner[_9_]

Help with cell reference
 

dim a as long
a=20
"=SUM(RC1:RC" & a & ")"
this will sum column 1 to column 20

Harjinder Singh Wrote:
Hi,

I am trying to sum of few cell wherein i am not sure what would be the
maximum cell.

for example if i am using the below given formula it givs me the som
of
cell one to cell four but i do not want the static result.
"=SUM(RC[1]:RC[4])"

will it possible if I assign a value to a variable:

like

a=20
and use the formula like this:

"=SUM(RC[1]:RC[a])"

- Harry

*** Sent via Developersdex http://www.developersdex.com **


--
kwiklearne
-----------------------------------------------------------------------
kwiklearner's Profile: http://www.excelforum.com/member.php...fo&userid=3190
View this thread: http://www.excelforum.com/showthread.php?threadid=52306


Tom Ogilvy

Help with cell reference
 
the formula you show actually sums the 4 cells to the right of the cell
containing the formula.

You can supply a variable

a = 20
activecell.formulaR1C1 = "=Sum(RC[1]:RC[" & a & "])"

--
Regards,
Tom Ogilvy


"Harjinder Singh" wrote:



Hi,

I am trying to sum of few cell wherein i am not sure what would be the
maximum cell.

for example if i am using the below given formula it givs me the some of
cell one to cell four but i do not want the static result.
"=SUM(RC[1]:RC[4])"

will it possible if I assign a value to a variable:

like

a=20
and use the formula like this:

"=SUM(RC[1]:RC[a])"

- Harry

*** Sent via Developersdex http://www.developersdex.com ***



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

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