Consulting

Results 1 to 4 of 4

Thread: Dynamic Formula put in formula with VBA

  1. #1
    VBAX Regular
    Joined
    Jul 2010
    Posts
    6
    Location

    Dynamic Formula put in formula with VBA

    I have VBA code creating X number of weeks in columns. Each week consists of M-F(Columns 1-5), and then a total of that weeks numbers(Column 6). And then say X = 2, I would have a 'Grand Total' in Column 13. Column 6 and 12 have totals from M-F(got that formula from Selection.FormulaR1C1 = "=SUM(R[0]C[-1]:R[0]C[-5]"), but then I need a formula to put in Column 13. The formula for X = 2 would be this, "=SUM(R[0]C[-1],R[0]C[-7])". How would I write the formula so that it will change with X. (ex. X=3, "=SUM(R[0]C[-1],R[0]C[-7],R[0]C[-13])" )

    Any and all help is appreciated!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Where does X come from? How does M-F make 5 columns?

    An example would make it all clearer.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2010
    Posts
    6
    Location
    X comes from a user inputbox that pops up and the user puts an integer in the text field.

    The actual process is making all 7 days of the week for each week, then converting saturday(using a weekday(currentcell) = 7) to be the column for M-F totals. and then deleting the sunday column.

    After the loop is done with all X, I have just a line of code labeling the last necessary column as "Grand Total". And then need a way of creating the formula to write in that column to get the 'sum of the sums'(sum of the weekly totals).

    I am new to this forum, can we post files up here? or what kind of example you looking for?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can post files. Use the Go Advanced button, then manage files. Talk through an example with that workbook data.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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