Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to extend the active range | Excel Discussion (Misc queries) | |||
How can change range to select active rows instead of :=Range("S10 | Excel Discussion (Misc queries) | |||
use active cell to determine range | Excel Discussion (Misc queries) | |||
Clearly seeing active cell in a range | Excel Discussion (Misc queries) | |||
Active range/selection? | Excel Worksheet Functions |