Results 1 to 6 of 6

Thread: Formula Vs FormulaR1C1 To Pass Calculation Range Through VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Post Formula Vs FormulaR1C1 To Pass Calculation Range Through VBA

    Hi All,

    I am trying to build a SUM function throughout my VBA code by getting the addresses of the relevant cells which need to be part of the SUM function. Somthing like this:
    Code:
    sFormula="=SUM("
    more code...
    sFormula = sFormula & .Offset(1, 1).Address(False, False) & ", "
    Then I remove the extra comma at the end of this string formula before trying to assign it to several formulas of adjacent cells since they need to sum as follows:

    Code:
    Range("B29").Select
    ActiveCell.Formula = sFormula
    ActiveCell.Resize(, 4).Select
    Selection.Formula = sFormula
    This isn't working and the SUM function isn't working either. I update related cells and the sum still remains zero. What is going on and how do I fix this so I can build the SUM function in the code and later on use the appropriate cell addresses as part of the SUM function so that I can assign it to several adjecent cells formula. Is this something to do with FormulaR1C1 style?


    I also recorded the following macro which is what I basically am trying to do which isn't working:

    Code:
    Range("B29").Select
        ActiveCell.FormulaR1C1 = "=SUM(R[-9]C,R[-6]C,R[-3]C)"
        Range("B29").Select
        Selection.AutoFill Destination:=Range("B29:E29"), Type:=xlFillDefault
    Thanks for your help.
    Last edited by labkhand; 10-17-2013 at 06:33 AM.

Similar Threads

  1. Replies: 2
    Last Post: 08-17-2013, 08:37 PM
  2. Replies: 7
    Last Post: 04-21-2013, 07:50 PM
  3. Formula Following Order Of Calculation BODMAS
    By paul_pearson in forum Excel Help
    Replies: 7
    Last Post: 03-27-2013, 02:07 PM
  4. VBA To Pass A Variable In An Excel Formula
    By devcon in forum Excel Help
    Replies: 4
    Last Post: 12-17-2012, 09:12 PM
  5. Replies: 11
    Last Post: 10-07-2012, 12:05 AM

Posting Permissions

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