Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel Macro (2003)

    I am trying to create a simple macro that will add a column of number above a blank cell, which will include all contiguous numbers heading vertically above the blank cell. My macro is always limited to the # of cells vertically when recording the macro.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel Macro (2003)

    If you want to take all possibilities into account, the macro wouldn't be simple any more. Here is a relatively naive version that places a SUM formula in the active cell:

    Sub CreateSumFormula()
    Dim rngTop As Range
    Dim rngBottom As Range
    ActiveCell.ClearContents
    Set rngBottom = ActiveCell.End(xlUp)
    Set rngTop = rngBottom.End(xlUp)
    ActiveCell.Formula = "=SUM(" & rngTop.Address(False, False) & _
    ":" & rngBottom.Address(False, False) & ")"
    End Sub

Posting Permissions

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