+ Reply to Thread
Results 1 to 6 of 6

Formula works but not when part of the main formula?

  1. #1
    Registered User
    Join Date
    09-21-2013
    Location
    Huntsville, Al
    MS-Off Ver
    Excel 2010
    Posts
    2

    Formula works but not when part of the main formula?

    I created a formula this morning for checking stock of an item in my excel sheet by searching for the item, then checking for the subitem under that item, and then reporting the stock which is listed next to that sub item. Sub items are repeated but main items are not, so I had to search for the main, then INDEX the array where the sub items are located so I can pull the stock values.

    I got everything to work.

    Then I decided to put the stock numbers onto another worksheet so I can keep the stock sheet separate from my other worksheets and pull from one master stock instead of copying stock to every sheet where I am finding these items. Then the problems began in converting the formula to pull from that new stock sheet.

    Now I am stumped.

    My master formula has transformed so far to:
    =INDEX(("Stock!"&ADDRESS(MATCH(LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),11)&":"&ADDRESS(MATCH("Total "&LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),11)),MATCH(LEFT(D5,FIND(" ",D5,1)-1),"Stock!"&ADDRESS(MATCH(LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),4)&":"&ADDRESS(MATCH("Total "&LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),4)),1)

    and instead of the stock value, it returns #VALUE

    When I run through calculation steps to find the error it shows:
    INDEX("Stock!$K$101:$K$107",MATCH("110v","Stock!$D101:D$107"),1)

    and calculates to:
    INDEX("Stock!$K$101:$K$107",#VALUE!,1)

    However, when I take this formula:
    =MATCH("110v",Stock!D101:D107)

    and apply it on its own, the value comes out as 2, no problems. Why am I getting a #VALUE! problem with the main formula when inputting the same exact part that's a problem returns a real value?

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Formula works but not when part of the main formula?

    you will either need indirect() to to build that function or maybe come other way
    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

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

    Re: Formula works but not when part of the main formula?

    Assuming that the logic of your formula is correct, you need to put the "built" range addresses inside the INDIRECT function.

    =INDEX(INDIRECT("Stock!"&ADDRESS(MATCH(LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),11)&":"&ADDRESS(MATCH("Total "&LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),11)),MATCH(LEFT(D5,FIND(" ",D5,1)-1),INDIRECT("Stock!"&ADDRESS(MATCH(LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),4)&":"&ADDRESS(MATCH("Total "&LEFT(T5,FIND(":",T5,1)-1),Stock!C:C,0),4)),1))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Formula works but not when part of the main formula?

    you will either need indirect() to to build that function or maybe come other way
    it needs to end up like this
    =INDEX(INDIRECT("Stock!$K$101:$K$107"),MATCH("110v",INDIRECT("Stock!$D101:D$107"),0),1)
    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  5. #5
    Registered User
    Join Date
    09-21-2013
    Location
    Huntsville, Al
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Formula works but not when part of the main formula?

    Plugging in "INDIRECT" to the two spots as suggested fixed the issue. I never really understood that function very well. I was using it in the beginning, then found it worked without it, but back to the same problem when I used the new sheet in the code.

  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: Formula works but not when part of the main formula?

    Good deal. 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)

Similar Threads

  1. Replies: 3
    Last Post: 09-26-2012, 04:29 PM
  2. Require information on how a specific formula works (see inside for formula)
    By twiggywales in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-04-2012, 10:13 AM
  3. [SOLVED] Error when using a formula as a macro even though the formula works..
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2011, 05:15 PM
  4. Formula works in dummy sheet but doesnt in the main workbook
    By amid in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-16-2009, 06:45 AM
  5. [SOLVED] Formula expected end of statement error, typing formula into cell as part of VBA macro
    By DavidGMullins@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2006, 03:05 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