+ Reply to Thread
Results 1 to 7 of 7

Function similar to "Sumif"

  1. #1
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    604

    Function similar to "Sumif"

    I have Categories (eg. A, N, W, CC, 695, 40, 44...etc) in Sheet1 Column B. I have Amounts (eg. numbers) in Sheet1 Column C. **See ATTACHED**

    I would like a function that will take numerous Categories as inputs and will return the sum of all the Category amounts combined.

    For instance, if I were to type the following formula into ANY cell in the workbook. Here would be the results:

    Please Login or Register  to view this content.
    ***The Categories will ALWAYS be in Sheet1 ColumnB and the amounts will ALWAYS be in Sheet1 ColumnC***
    ***I would like this function to work regardless of the sheet it is entered into in the workbook**
    Attached Files Attached Files
    Last edited by Xx7; 06-02-2012 at 01:48 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Function similar to "Sumif"

    Xx7,

    To use specified ranges from anywhere in a workbook, you should setup a dynamic named ranges.

    For the Categories, create a named range and call it rngCategories and use this formula:
    Please Login or Register  to view this content.
    For the Amounts, create a named range and call it rngAmounts and use this formula:
    Please Login or Register  to view this content.

    Then, anywhere in the workbook, you can put in this formula to get the desired results:
    Please Login or Register  to view this content.

    Change the part in blue to whatever you'd like
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    604

    Re: Function similar to "Sumif"

    Quote Originally Posted by tigeravatar View Post
    Then, anywhere in the workbook, you can put in this formula to get the desired results:
    Please Login or Register  to view this content.
    Change the part in blue to whatever you'd like
    That's great and works exactly the way I want it to.

    However, the individuals using the workbook will get confused by the formula above. Is it possible to convert this into a function? How would I do this


    For example, to get the same result I would like to only enter this (or something similar) into the cell:
    =LEAD(A,U)

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Function similar to "Sumif"

    Xx7,

    If native excel formulas aren't an option, here's a UDF that will perform as requested. Make sure it is placed in a standard module within the workbook that will need its functionality:
    Please Login or Register  to view this content.


    Here are some examples for how to use it:
    =LEAD("A,U")
    =LEAD("CC,61,54,43")
    =LEAD("A,U,C,W,CC,KK,TT.1,695,40,54,43")

  5. #5
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    604

    Re: Function similar to "Sumif"

    Exactly what I was looking for! thanks

  6. #6
    Forum Contributor
    Join Date
    01-30-2011
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    604

    Re: Function similar to "Sumif"

    This function works before I save the file. I put it in Module1 in the workbook. But after I save it as a macro-enabled workbook I get a #NAME? error? What is the reason for this?

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Function similar to "Sumif"

    Whenever you open a file that contains macros, you'll have to tell Excel to enable macros, or the VBA code won't work. If you're not getting a prompt to enable macros when you open the workbook, you'll need to change your macro security settings in the trust center

+ 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