Results 1 to 3 of 3

Summation across of a variable amount of columns VBA formula

Threaded View

  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    59

    Summation across of a variable amount of columns VBA formula

    I'm trying to enter the summation formula into three
    columns that vary in placement based on the value of num_objs. Basically, the number of grey columns in each of the three sets will equal num_objs. I want the user to be able to enter values into the grey columns in the middle section and the values of the two rightmost white columns (with '0's in them currently) will change accordingly.

    My current code is below. However, I keep getting a compile error saying "Expected: end of statement".

    I've been searching for a solution online for a couple days now, and I don't see how my code is different than what I've been seeing of other people using variables in their formulas.

       Dim curr_sum As Integer
       curr_sum = 13 + num_objs
       Dim transfer_sum As Integer
       transfer_sum = 13 + num_objs + num_objs + 1
       Dim post_start As Integer
       post_start = 13 + num_objs + 1
       Dim post_sum As Integer
       post_sum = 13 + num_objs + num_objs + num_objs + 2
    
       'fill the "total" columns with the correct sums
       For total_row = 6 To 99
           Cells(total_row, curr_sum).FormulaR1C1 = _
               "=SUM(R"&total_row&"C13:R"&total_row&"C"&curr_sum -1&")"
           Cells(total_row, transfer_sum).FormulaR1C1 = "=SUM(RC[-"&num_objs&"]:RC[-1])"
           Cells(total_row, post_sum).FormulaR1C1 = "=SUM(RC[-"&num_objs"]:RC[-1])"
       Next total_row
    Thanks for all your help.
    Attached Images Attached Images
    Last edited by Kaigi; 06-04-2009 at 11:08 PM.

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