+ Reply to Thread
Results 1 to 2 of 2

Autosum in a Macro

  1. #1
    Registered User
    Join Date
    11-30-2006
    Posts
    15

    Autosum in a Macro

    Hi,

    I have a Marco, which i run on data of variable length, each month. The Macro populates Formulas in different parts of the Workbook.

    Some months, it will have to Sum 4 fields, =Sum(J1:J4) and others a completely different amount of fields =Sum(J1:J36).

    The Auto Sum function on the workbook always picks up the right fields, it=s there a way i can insert this into the code? the current line is

    .Range("I" & intRow).formula = '{I'd like this to be AutoSum, might need to change the .formula}

    Thanks in advance for any help or advice that you provide.

    Ian

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    If you can find the number of rows to sum (row_count), the formula to place in the sum cell will be:

    Cells(row_count + 1,col_number).FormulaR1C1="=SUM(R[-row_count]C:R[-1]C)"

    e.g. to place the formula =Sum(J1:J10) in J11, the code would be

    Cells(11,10).FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"

    Note this is for a single column sum.

+ 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