+ Reply to Thread
Results 1 to 8 of 8

Sumproduct with Sheet as variable

Hybrid View

  1. #1
    Registered User
    Join Date
    04-29-2016
    Location
    Czech Republic / Germany
    MS-Off Ver
    Excel 2010
    Posts
    6

    Sumproduct with Sheet as variable

    Hi,
    I am trying to use a R1C1 Sumproduct formula with a variable sheet, but I got stuck in this problem. I try to use the string "str" as the variable, yet Excel responds with run-time error 1004.
    Any hints,please?

    Here the code:
    For Each sh In Sheets
    str = sh.Name
    Sheets("Übersicht").Range("C" & 14 + i).Select
        ActiveCell.FormulaR1C1 = _
            "=SUMPRODUCT((R14C='& str & '!R2C7:R71C7)*('& str & '!R1C10:R1C13=Übersicht!R[-3]C)*' & str & '!R2C10:R71C13))"
    Next sh
    Thank you very much!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Sumproduct with Sheet as variable

    Try this...

    For Each sh In Sheets
        Str = sh.Name
        Sheets("Übersicht").Range("C" & 14 + i).FormulaR1C1 = _
            "=SUMPRODUCT((R14C='" & Str & "'!R2C7:R71C7)*('" & Str & "'!R1C10:R1C13=Übersicht!R[-3]C)*'" & Str & "'!R2C10:R71C13))"
    Next sh


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,065

    Re: Sumproduct with Sheet as variable

    When you refer to str you are talking to VBA so the str reference should be outside double quotes

    Try

    "=SUMPRODUCT((R14C='" & str & "'!R2C7:R71C7)*('" & str & "'!R1C10:R1C13=Übersicht!R[-3]C)*'" & str & "'!R2C10:R71C13))"
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  4. #4
    Registered User
    Join Date
    04-29-2016
    Location
    Czech Republic / Germany
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Sumproduct with Sheet as variable

    Thank you for quick reply, Sixthsense and Special-K.
    However, the proposed solution doesn't work. It stills reports error when it comes to the line with Sumproduct...

  5. #5
    Valued Forum Contributor meabrams's Avatar
    Join Date
    10-03-2014
    Location
    USA
    MS-Off Ver
    2007, 2010, 2013, 2016
    Posts
    451

    Re: Sumproduct with Sheet as variable

    what is the formula suppose to look like when it is in the cell (after the macro would have entered it)

  6. #6
    Registered User
    Join Date
    04-29-2016
    Location
    Czech Republic / Germany
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Sumproduct with Sheet as variable

    Hi meabrams, thanks for response.
    =SUMMENPRODUKT((C$14='420003(BayerischeMotorenwerke)'!$G$2:$G$71)*('420003(BayerischeMotorenwerke)'!$J$1:$M$1=Übersicht!$C$12)*('420003(BayerischeMotorenwerke)'!$J$2:$M$71))
    420003(BayerischeMotorenwerke) is the name of a sheet and it should vary depending on the string 'str'.

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Sumproduct with Sheet as variable

    Hi,

    You have one too many closing brackets in your formula

    Sheets("Übersicht").Range("C" & 14 + i).FormulaR1C1 = _
            "=SUMPRODUCT((R14C='" & str & "'!R2C7:R71C7)*('" & str & "'!R1C10:R1C13=Übersicht!R[-3]C)*'" & str & "'!R2C10:R71C13)"
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  8. #8
    Registered User
    Join Date
    04-29-2016
    Location
    Czech Republic / Germany
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Sumproduct with Sheet as variable

    Hi xlnitwit,
    thanks for your help, that was it!

+ 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. SUMPRODUCT with Variable Year
    By gladiatorx in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-21-2013, 11:07 PM
  2. [SOLVED] VBA Sumproduct Variable Query
    By mowens74 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-19-2013, 09:59 PM
  3. [SOLVED] SumProduct Formula with variable
    By rizmomin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-18-2012, 01:28 PM
  4. variable in to input data into variable named sheet and if does not exist create
    By rwhidden in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-30-2011, 12:08 AM
  5. Sumproduct with variable range
    By shawn212 in forum Excel General
    Replies: 3
    Last Post: 07-30-2010, 09:53 AM
  6. SUMPRODUCT Syntax with Variable VBA
    By jaslake in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2009, 12:57 AM
  7. Sumproduct using variable time
    By reggie1000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-20-2009, 01:40 PM
  8. sumproduct - reading a variable value
    By redneck joe in forum Excel General
    Replies: 3
    Last Post: 05-24-2006, 03:02 PM

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