Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Formual Issue

Hi,

Simple formula to insert a SUM.

Range("G22").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(G5:R[-2]C)"

But it returns in Excel......=SUM('G5':G124)
which doesn't work.

Any idea?

Thanks John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,886
Default Formual Issue

Hi John

I can't see why you are selecting G22, but wanting the formula to run
from G5.

Try the following

Sub test4()
Dim lr As Long
Range("G5").Select
lr = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
Cells(Rows.Count, ActiveCell.Column).End(xlUp)(3).Select
ActiveCell.Formula = "=Sum(" & "G5:G" & lr & ")"

End Sub

Amend to suit
--
Regards

Roger Govier


"John" wrote in message
...
Hi,

Simple formula to insert a SUM.

Range("G22").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(G5:R[-2]C)"

But it returns in Excel......=SUM('G5':G124)
which doesn't work.

Any idea?

Thanks John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Formual Issue

Can't see why i delected G22 either. Your formula worked spot on though.

Cheers Roger

"Roger Govier" wrote:

Hi John

I can't see why you are selecting G22, but wanting the formula to run
from G5.

Try the following

Sub test4()
Dim lr As Long
Range("G5").Select
lr = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
Cells(Rows.Count, ActiveCell.Column).End(xlUp)(3).Select
ActiveCell.Formula = "=Sum(" & "G5:G" & lr & ")"

End Sub

Amend to suit
--
Regards

Roger Govier


"John" wrote in message
...
Hi,

Simple formula to insert a SUM.

Range("G22").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(G5:R[-2]C)"

But it returns in Excel......=SUM('G5':G124)
which doesn't work.

Any idea?

Thanks John




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,886
Default Formual Issue

Hi John

Can't see why i delected G22 either.

Glad it just wasn't me!!!

Thanks for the feedback, pleased you got it to work

--
Regards

Roger Govier


"John" wrote in message
...
Can't see why i delected G22 either. Your formula worked spot on
though.

Cheers Roger

"Roger Govier" wrote:

Hi John

I can't see why you are selecting G22, but wanting the formula to run
from G5.

Try the following

Sub test4()
Dim lr As Long
Range("G5").Select
lr = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
Cells(Rows.Count, ActiveCell.Column).End(xlUp)(3).Select
ActiveCell.Formula = "=Sum(" & "G5:G" & lr & ")"

End Sub

Amend to suit
--
Regards

Roger Govier


"John" wrote in message
...
Hi,

Simple formula to insert a SUM.

Range("G22").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(G5:R[-2]C)"

But it returns in Excel......=SUM('G5':G124)
which doesn't work.

Any idea?

Thanks John






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Formual Issue

with a macro you have to use the row/column method of identifying a
cell in a formula - when i record =sum(blah:blah), this is what you get
in the VBA editor:

ActiveCell.FormulaR1C1 = "=SUM(R[-10]C:R[-2]C)"

(don't use this specific one - it doesn't sum as many rows as you
wanted).
susan



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Formual Issue

To the best of my knowledge you can't combine R1C1 and A1 reference
styles. Try This:
Range("G22").End(xlDown).Offset(2).FormulaR1C1 = "=SUM(R5C:R[-2]C)"

HTH

Charles Chickering
John wrote:
Hi,

Simple formula to insert a SUM.

Range("G22").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
ActiveCell.FormulaR1C1 = "=SUM(G5:R[-2]C)"

But it returns in Excel......=SUM('G5':G124)
which doesn't work.

Any idea?

Thanks John


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
Date formual issue Martyn Excel Worksheet Functions 2 March 25th 08 08:04 PM
8000 formual issue Chris Excel Discussion (Misc queries) 1 September 5th 07 08:21 PM
Formual Jodi Excel Worksheet Functions 1 May 16th 07 01:03 AM
WHAT DOES FORMUAL =C8+ 15 DO Tara Excel Discussion (Misc queries) 1 January 4th 07 03:38 PM
what is mean by ^ in formual khan Excel Programming 2 October 13th 05 12:16 PM


All times are GMT +1. The time now is 03:07 PM.

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

About Us

"It's about Microsoft Excel"