Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default A little help with cell reference please


From VB code I want to write a formula into the selected cell that will
add up the 10 cells to the right of the selected cell. I do not know the
location of the selected cell so I want some form of relative sum() formula.

ie =sum('from here', +1, +10) along the row.

I bet it is very simple but I cannot find anything in the help. All the
ones I can find expect you to know where you are starting from!

Thanks
Brian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default A little help with cell reference please


myVar = Application.SUM(Activecell.Resize(,10))

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Ashnook" <brian@atashnookcdtfreeservedotcodotuk wrote in message
. com...

From VB code I want to write a formula into the selected cell that will
add up the 10 cells to the right of the selected cell. I do not know the
location of the selected cell so I want some form of relative sum()

formula.

ie =sum('from here', +1, +10) along the row.

I bet it is very simple but I cannot find anything in the help. All the
ones I can find expect you to know where you are starting from!

Thanks
Brian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default A little help with cell reference please

Bob Phillips wrote:
myVar = Application.SUM(Activecell.Resize(,10))


Hi BOB, thanks for the swift reply, this gives me a #NAME? result? I
have tried other number and combination with no success. mu selected
cell in this try is B5, but it could be anything.

Brian
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default A little help with cell reference please

Brian,

Bob's formula is not only elegant, but it works for me :

Sub Macro1()
ActiveCell.Value = Application.Sum(ActiveCell.Resize(, 11))
End Sub

HTH
Cheers
Carim

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default A little help with cell reference please

Carim wrote:
Brian,

Bob's formula is not only elegant, but it works for me :

Sub Macro1()
ActiveCell.Value = Application.Sum(ActiveCell.Resize(, 11))
End Sub

HTH
Cheers
Carim

I may be misleading you, I want to write the formule in to the cell not
the result of the sum. This is so that whenever changes are made in the
10 right cells to sum in the selected cell changes accordingly.

The Vb code has to write the formula into the selected cell.

Brian


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default A little help with cell reference please

Brian,

I do not understand your requirement :

1. Either you want the formula in your cell, then the code is :
Sub Macro1()
ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[10])"
End Sub
2. Or you want the sum itself to appear, then the code is :
Sub Macro1()
ActiveCell.Value = Application.Sum(ActiveCell.Resize(, 11))
End Sub

Hope this clarifies
Cheers
Carim

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default A little help with cell reference please

Hi Brian,

Something along this line :

ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[10])"

HTH
Cheers
Carim

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default A little help with cell reference please

Carim wrote:
Hi Brian,

Something along this line :

ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[10])"

HTH
Cheers
Carim

Thanks Carim for the swift reply, this solution means (I think) that I
have to turn on RC referencing for the whole sheet and I don't want to
do that if possible.

Brian
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default A little help with cell reference please

Try it. You'll be pleasantly surprised how smart VBA and Excel work together.

Ashnook wrote:

Carim wrote:
Hi Brian,

Something along this line :

ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[10])"

HTH
Cheers
Carim

Thanks Carim for the swift reply, this solution means (I think) that I
have to turn on RC referencing for the whole sheet and I don't want to
do that if possible.

Brian


--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default A little help with cell reference please

Dave Peterson wrote:
Try it. You'll be pleasantly surprised how smart VBA and Excel work together.

Ashnook wrote:
Carim wrote:
Hi Brian,

Something along this line :

ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[10])"

HTH
Cheers
Carim

Thanks Carim for the swift reply, this solution means (I think) that I
have to turn on RC referencing for the whole sheet and I don't want to
do that if possible.

Brian


I may be misleading you, I want to write the formula in to the cell not
the result of the sum. This is so that whenever changes are made in the
10 right cells to sum in the selected cell changes accordingly.

The Vb code has to write the formula into the selected cell. When you
re-select the originally selected cell the =bar should show and =formula
not the result of the sum.

Brian


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default A little help with cell reference please

Give it a try.



Ashnook wrote:

Dave Peterson wrote:
Try it. You'll be pleasantly surprised how smart VBA and Excel work together.

Ashnook wrote:
Carim wrote:
Hi Brian,

Something along this line :

ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[10])"

HTH
Cheers
Carim

Thanks Carim for the swift reply, this solution means (I think) that I
have to turn on RC referencing for the whole sheet and I don't want to
do that if possible.

Brian


I may be misleading you, I want to write the formula in to the cell not
the result of the sum. This is so that whenever changes are made in the
10 right cells to sum in the selected cell changes accordingly.

The Vb code has to write the formula into the selected cell. When you
re-select the originally selected cell the =bar should show and =formula
not the result of the sum.

Brian


--

Dave Peterson
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
Changing sheet reference to cell reference TeeJay Excel Worksheet Functions 3 October 19th 07 11:50 AM
Formulas that reference cells that reference another cell Andrea Excel Discussion (Misc queries) 7 October 19th 06 08:14 AM
absolute cell reference A spreadsheet cell reference that does no help Excel Discussion (Misc queries) 1 January 18th 06 06:56 PM
problem with cell reference in =sum(offset(cell reference,x,y,z,a)). Want cell ref to be variable. [email protected] Excel Worksheet Functions 2 December 11th 04 12:05 AM
Problem with =sum(offset(cell reference,w,x,y,z). I want cell reference to be variable [email protected] Excel Worksheet Functions 2 December 11th 04 12:00 AM


All times are GMT +1. The time now is 08:30 PM.

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"