Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Formula - Dynamic Range

Based on the current activecell, I want to create a median calculation that
will include the continuous range which is directly above the active cell.
So, if the Activecell were A10 and there was a range of data in cells A5:A9,
I would want to include in cell A10 = Median(A5:A9). The code needs to be
dynamic so that it includes the continuous range directly above the cell,
which will vary. Thanks.

Activecell.FormulaR1C1 = ?????

Jason
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Formula - Dynamic Range

try this

firstrow = ActiveCell.Offset(-1, 0).End(xlUp).Row
actcolumn = ActiveCell.Column
lastrow = ActiveCell.Row - 1

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & lastrow & ")"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Formula - Dynamic Range

Joel,

That almost gets me there... it is accurately pulling the beginning row and
the ending row, but for some reason it is including more columns than just
the current column. So for example, based on my sample data of the subject
being A5:A9, instead of Median($A$5:$A$9), it is giving me Median($A$5:$Y$9).
Any suggestions on how I can modify to fix this. Thanks for your help.

"Joel" wrote:

try this

firstrow = ActiveCell.Offset(-1, 0).End(xlUp).Row
actcolumn = ActiveCell.Column
lastrow = ActiveCell.Row - 1

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & lastrow & ")"


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Formula - Dynamic Range

I made a typo

from
ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & lastrow & ")"

to
ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & actcolumn & ")"

"Jason" wrote:

Joel,

That almost gets me there... it is accurately pulling the beginning row and
the ending row, but for some reason it is including more columns than just
the current column. So for example, based on my sample data of the subject
being A5:A9, instead of Median($A$5:$A$9), it is giving me Median($A$5:$Y$9).
Any suggestions on how I can modify to fix this. Thanks for your help.

"Joel" wrote:

try this

firstrow = ActiveCell.Offset(-1, 0).End(xlUp).Row
actcolumn = ActiveCell.Column
lastrow = ActiveCell.Row - 1

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & lastrow & ")"


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Formula - Dynamic Range

Figured it out. Made the following change and it worked. Thanks again.

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & actcolumn & ")"

"Jason" wrote:

Joel,

That almost gets me there... it is accurately pulling the beginning row and
the ending row, but for some reason it is including more columns than just
the current column. So for example, based on my sample data of the subject
being A5:A9, instead of Median($A$5:$A$9), it is giving me Median($A$5:$Y$9).
Any suggestions on how I can modify to fix this. Thanks for your help.

"Joel" wrote:

try this

firstrow = ActiveCell.Offset(-1, 0).End(xlUp).Row
actcolumn = ActiveCell.Column
lastrow = ActiveCell.Row - 1

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & lastrow & ")"




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Formula - Dynamic Range

Since you're in the same column:
ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C:R" & lastrow & "C)"

or
ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C:R[-1]C)"

Which means to add the value in the first row of the same column through the
cell right above the cell with the formula.





Jason wrote:

Figured it out. Made the following change and it worked. Thanks again.

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & actcolumn & ")"

"Jason" wrote:

Joel,

That almost gets me there... it is accurately pulling the beginning row and
the ending row, but for some reason it is including more columns than just
the current column. So for example, based on my sample data of the subject
being A5:A9, instead of Median($A$5:$A$9), it is giving me Median($A$5:$Y$9).
Any suggestions on how I can modify to fix this. Thanks for your help.

"Joel" wrote:

try this

firstrow = ActiveCell.Offset(-1, 0).End(xlUp).Row
actcolumn = ActiveCell.Column
lastrow = ActiveCell.Row - 1

ActiveCell.FormulaR1C1 = "=median(R" & firstrow & "C" & actcolumn & _
":R" & lastrow & "C" & lastrow & ")"



--

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
Formula for Dynamic Range? VCUE New Users to Excel 3 October 6th 07 07:56 AM
Cant get dynamic range formula to work. Mike K Excel Worksheet Functions 2 May 4th 07 11:59 PM
Copying Formula into a Dynamic Range Big H Excel Programming 0 October 23rd 06 11:34 PM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
formula to set up dynamic range in names Jeff Excel Worksheet Functions 0 February 23rd 05 03:45 PM


All times are GMT +1. The time now is 10:18 AM.

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"