+ Reply to Thread
Results 1 to 9 of 9

SUM formula, target is in a sheet with a variable name

  1. #1
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    SUM formula, target is in a sheet with a variable name

    Hi,

    I have what is certainly a basic problem, but I am stuck.
    In the first sheet "Sheet1", I am trying to SUM the values of column C from another sheet 'XXX'. The trick is that the name of this other sheet is a variable, like Sheets(1+i).name , "i" being an integer. I can't find the proper syntax for the formula below.

    Any help would be appreciated.
    Thank you!

    PHP Code: 
    ActiveCell.FormulaR1C1 "=SUM(XXX!C[1])" 

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: SUM formula, target is in a sheet with a variable name

    You did not provide a file for testing so this has not been tested but it compiles. This is the idea:

    Please Login or Register  to view this content.
    The single quotes are necessary in case the sheet name contains spaces.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: SUM formula, target is in a sheet with a variable name

    Thank you for the help!

    Unfortunately, this solution doesn't work. I think that I have tried every combination of ' " "" """ &, with no success (Thank you for explaining the reason of the ', I didn't know that). I have retried yours, and even if it compiles, I get a Run-time error 438: Object doesn't support this property or method when I activate the sub.

    I have attached the relevant part of my current project. It is not very nice after I have removed whatever should not be here, but I hope that it is clear enough.

    -Only the 2 first sheets are required; just press the orange button in sheet "Export".
    -In module 1, the problematic part is at the end, between the two '++++++++ lines. You can also toggle the 2 ActiveCell lines by toggling the '

    Thank you again!

    Test.xlsm

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: SUM formula, target is in a sheet with a variable name

    Taking a look at my post I realized that it is wrong. I haven't looked at your file yet but if you try this correction it may solve it. When I get more time later I'll take a closer look.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-25-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    434

    Re: SUM formula, target is in a sheet with a variable name

    Quote Originally Posted by 6StringJazzer View Post
    Taking a look at my post I realized that it is wrong. I haven't looked at your file yet but if you try this correction it may solve it. When I get more time later I'll take a closer look.

    Please Login or Register  to view this content.
    slight change
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: SUM formula, target is in a sheet with a variable name

    Thank you to both of you. I had some trouble to adopt it to my project, but it is finally working.

    Nevertheless, if you won't mind to devote more of your time to this issue, I would have another related question. When I don't use the relative reference (ie C[1]) but the reference of the column, I get weird things instead.
    PHP Code: 
        ActiveCell.FormulaR1C1 "=SUM('" Sheets(i).Name "'!E:E)"                        
        
    ActiveCell.FormulaR1C1 "=SUM('" Sheets(1).Range("A" i).Value "'!E:E)" 
    both return
    =SUM('AAA'!E:(E))
    What would be the correct syntax to get SUM('AAA'!E:E) as expected?
    Thank you again!

  7. #7
    Forum Contributor
    Join Date
    01-25-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    434

    Re: SUM formula, target is in a sheet with a variable name

    change ActiveCell.FormulaR1C1
    to ActiveCell.Formula
    Last edited by ThirtyTwo; 06-06-2014 at 05:28 PM.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: SUM formula, target is in a sheet with a variable name

    ThirtyTwo, no need to quote an entire post to respond to it, adds a lot of volume to the thread. Especially true when your response is immediately after the post you are responding to (see rule #12). Thanks.

  9. #9
    Registered User
    Join Date
    10-17-2011
    Location
    Seattle, USA
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: SUM formula, target is in a sheet with a variable name

    Thank you again to both of you, it is very helpful

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Commission Calculator ( % to target with variable % pay rate)
    By firefuze in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-19-2013, 06:06 PM
  2. [SOLVED] for each sheet with first 3 char matching variable, copy column C to Target sheet unless..
    By Spyderz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2012, 08:17 AM
  3. Worksheet_CHange (ByVal Target as Range) when target is formula cell
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 07:00 PM
  4. Variable VLOOKUP source and target
    By Vindaloo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-11-2006, 10:56 AM
  5. Sumif with variable target
    By Brisbane Rob in forum Excel General
    Replies: 2
    Last Post: 03-23-2006, 07:20 AM

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