Consulting

Results 1 to 4 of 4

Thread: Solved: HELP me figure out how to use the formula commands

  1. #1
    VBAX Newbie
    Joined
    Feb 2008
    Posts
    3
    Location

    Solved: HELP me figure out how to use the formula commands

    I am currently writing a macro that will calculate the median of the array of values above my active cell. Currently I have the following code:

    Sub median()
    '
    ' Median Macro
    ' Macro recorded 2/4/2008 by Daniel Mower
    '
    Range("B1").Select
    Selection.End(xlDown).Offset(2, 0).Select
    ActiveCell.FormulaR1C1 = "MEDIAN"
    ActiveCell.Next.Select
    ActiveCell.FormulaR1C1 = "=MEDIAN(R[-109]C:R[-2]C)"
    ActiveCell.Select
    Selection.Copy
    Range("C110:N110").Select
    Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Selection.Copy
    End Sub
    All this is grand, and does what I would like it to do. However, I need the size of the array to be exspansive. The FormulaR1C1 feature takes in a string. I need to somehow have the formula Calculate the median of the all the cells above.

  2. #2
    VBAX Regular
    Joined
    Sep 2007
    Location
    Singapore
    Posts
    63
    I think this may help; I didn't try it, though. Use this to replace the current line where you specify the formula.
    [vba]ActiveCell.FormulaR1C1 = "=MEDIAN(R1C2:R" & .Cells(1, 2).End(xlDown).Row & "C2)"[/vba]

  3. #3
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    Howdy, and welcome to the board. Is this question specific to Mac VBA?

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

  4. #4
    VBAX Newbie
    Joined
    Feb 2008
    Posts
    3
    Location
    Herzberg,

    Thanks, I think what you told me is along the right line. And it help me think of this

    Sub median()
    '
    ' Median Macro
    ' Macro recorded 2/4/2008 by Daniel Mower
    '
    Dim RowNum As String
    Range("B1").Select
    Selection.End(xlDown).Offset(2, 0).Select
    RowNum = (ActiveCell.Row - 1) * -1
    ActiveCell.FormulaR1C1 = RowNum '"MEDIAN"
    ActiveCell.Next.Select
    ActiveCell.FormulaR1C1 = "=MEDIAN(R[" & RowNum & "]C:R[-2]C)"
    Selection.Copy
    Range("C110:N110").Select
    Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Selection.Copy
    End Sub


    THANKS!!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •