Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sum active range

I am trying to write a macro that writes the formula to sum the active cells
in the cell below the acitve. If my range was the same size everytime it
would be simple, but the range is never the same size.

I was trying to store the active range and then recall the range in a
formula, but no luck with this method.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sum active range

Dim rng as Range, rng1 as Range
set rng = Selection
if rng.Areas.Count 1 then
msgbox "non contiguous areas selected - exiting"
exit sub
end if
if rng.columns.count 1 then
msgbox "multiple columns selected = exiting"
Exit sub
end if
set rng1 = rng(rng.count).offset(1,0)
rng1.Formula = "=Sum(" & rng.Address(1,1) & ")"

--
Regards,
Tom Ogilvy

"Judd Jones" <Judd wrote in message
...
I am trying to write a macro that writes the formula to sum the active

cells
in the cell below the acitve. If my range was the same size everytime it
would be simple, but the range is never the same size.

I was trying to store the active range and then recall the range in a
formula, but no luck with this method.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sum active range

Hi Judd,

Here is some VBA to create a formula as described

Dim cLastRow As Long

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Cells(cLastRow + 1, "A").Formula = "=SUM(" &
Range("A1").Resize(cLastRow, 1).Address & ")"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Judd Jones" <Judd wrote in message
...
I am trying to write a macro that writes the formula to sum the active

cells
in the cell below the acitve. If my range was the same size everytime it
would be simple, but the range is never the same size.

I was trying to store the active range and then recall the range in a
formula, but no luck with this method.




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
How to extend the active range Peter[_9_] Excel Discussion (Misc queries) 0 March 29th 09 06:39 PM
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
use active cell to determine range Gizmo Excel Discussion (Misc queries) 2 March 31st 08 04:55 AM
Clearly seeing active cell in a range dsa Excel Discussion (Misc queries) 2 March 24th 08 03:22 PM
Active range/selection? anita Excel Worksheet Functions 9 September 20th 06 01:35 PM


All times are GMT +1. The time now is 04:30 AM.

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"