Consulting

Results 1 to 6 of 6

Thread: Sum a range across multiple Worksheets

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Sum a range across multiple Worksheets

    I have a sheet called "Totals" which sums all the worksheet totals for each cell between the sheets called "FIRST" and "LAST"

    The formula that goes into each cell is like
    =SUM(First:Last!D3)
    Now what I want is to put the formula into each cell in a range so that it totals all the appropriate cells.

    How can I re-write it in VBA so that if a cell's calculated value is 0 or nothing it just gives me a blank " " else it calculates the cell's value.

    This works like this
    Range("D3:E666").Formula = "=Sum(First:Last!D3)"
    But when I try to do this to account for the cell's calculated value being zero

    Range("D3:E666").Formula = "=IF(SUM(First:Last!D3)=0,"",=SUM(First:Last!D3))"
    I get an error.

  2. #2
    Hi simora,

    Try this:

    Range("D3:E666").Formula = "=IF(SUM(First:Last!D3)=0,"""",SUM(First:Last!D3))"
    Regards,

    Robert

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks Robert.

    It worked perfectly.

    How would I re-write this .Formula = "=Sum(First:Last!D3)" So that the D3 refrences the ActiveCell in a Specific range.

    This will be going into a loop on another worksheet.

  4. #4
    I'm not really sure what you mean, but as a start this will put $B$2 into the formula:

    .Formula = "=Sum(First:Last!" & Range("B2").Address & ")"
    Does that help?

    Robert
    Last edited by Trebor76; 08-04-2015 at 06:25 PM.

  5. #5
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks Robert.

    I got it to work like this

    Cell.Formula = "=Sum(First:Last!" & Cell.Address & ")"
    Really Appreciated your help on this.

  6. #6

    Smile

    You're welcome

Posting Permissions

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