+ Reply to Thread
Results 1 to 2 of 2

using Formulas in VBA

  1. #1
    Alan M
    Guest

    using Formulas in VBA

    I need to be able to add the sum of a column of data into the cell at the
    bottom of the column. I can do this using

    ActiveCell.FormulaR1C1 = "=SUM(R[-121)]C:R[-1]C)"


    However this number of rows in the column may vary so I cannot use a
    pre-defined R1C1 range in the formula. Each time the code is run the number
    of rows may be more or less so the -121 will vary.

    How can I overcome this please?

  2. #2
    Bob Phillips
    Guest

    Re: using Formulas in VBA

    This will calculate the last used row in column A and put the formula in the
    next row

    Dim iLastRow As Long

    iLastRow = Cells(Rows.Count, "A").End(xlUp).row
    Cells(iLastRow + 1, "A").FormulaR1C1 = "=SUM(R[-" & iLastRow &
    "]C:R[-1]C)"


    --

    HTH

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


    "Alan M" <[email protected]> wrote in message
    news:[email protected]...
    > I need to be able to add the sum of a column of data into the cell at the
    > bottom of the column. I can do this using
    >
    > ActiveCell.FormulaR1C1 = "=SUM(R[-121)]C:R[-1]C)"
    >
    >
    > However this number of rows in the column may vary so I cannot use a
    > pre-defined R1C1 range in the formula. Each time the code is run the

    number
    > of rows may be more or less so the -121 will vary.
    >
    > How can I overcome this please?




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1