+ Reply to Thread
Results 1 to 10 of 10

Pass Variable in Formula

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Pass Variable in Formula

    Hello:

    I am using the below formula and i want to see if it is possible to pass variable in the formula to give the result.

    Please Login or Register  to view this content.
    N$2:$N$2000 needs to be variable.
    The value of variable can come from cell K1
    Example:
    If K1 = N then the above formula will stay as is.
    If K1 = M then above formula needs to change to :

    Please Login or Register  to view this content.
    I hope this is clear explanation.

    Please help and let me know if any questions.

    Thanks
    Riz

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Pass Variable in Formula

    Are those the only 2 variables?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Pass Variable in Formula

    Hello,

    Try this
    =IF(K1="N",SUMIFS(DailySales!$N$2:$N$2000,DailySales!$B$2:$B$2000,">="&$J7,DailySales!$B$2:$B$2000,"<="&$K7,DailySales!$A$2:$A$2000,L$1),IF(K1="M",SUMIFS(DailySales!$M$2:$M$2000,DailySales!$B$2:$B$2000,">="&$J7,DailySales!$B$2:$B$2000,"<="&$K7,DailySales!$A$2:$A$2000,L$1),"K1 is not N or M"))

    Hope this help.
    (copy pasta from Ford)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools

    Regards,
    Lem

  4. #4
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in Formula

    Hi Lenice and Tony:

    The value in cell K1 could be any Alphabet A-Z

    Hope this explains my requirement.

    Thanks

    Riz

  5. #5
    Valued Forum Contributor Lemice's Avatar
    Join Date
    04-13-2013
    Location
    Somewhere.
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Pass Variable in Formula

    I see,

    Try this formula then
    Please Login or Register  to view this content.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Pass Variable in Formula

    You're already using columns A and B for criteria.

    Something like this:

    =SUMIFS(INDEX(DailySales!$A$2:$Z$2000,,CODE(UPPER(K1))-64),DailySales!$B$2:$B$2000,">="&$J7,DailySales!$B$2:$B$2000,"<="&$K7,DailySales!$A$2:$A$2000,L$1)

    Assumes cell K1 will only contain letters A to Z.

  7. #7
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in Formula

    Hi Tony:

    This does not give correct result.
    Let me explain you.
    I have Daily Sales Data.
    Column N has Sales from Category1
    Column O has Sales from Category2
    Column P has Sales from Category3
    Column Q has Sales from Category4

    and so on.

    Please refer to attached excel sheet as an example.
    I have 5 stores and i compare data side by side
    Please let me know if any questions.

    Thanks
    Riz
    Attached Files Attached Files

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Pass Variable in Formula

    Try this:

    =SUMIFS(INDIRECT("DailySales!"&$K$1&":"&$K$1),DailySales!$B:$B,">="&$J7,DailySales!$B:$B,"<="&$K7,DailySales!$A:$A,L$1)

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Smile Re: Pass Variable in Formula

    Hi Tony:

    Looks like this works.
    Thanks a lot


    Riz

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Pass Variable in Formula

    You're welcome. Thanks for the feedback!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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