+ Reply to Thread
Results 1 to 17 of 17

Array formula and parentheses

  1. #1
    Registered User
    Join Date
    12-21-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Array formula and parentheses

    hi guys,

    this is a cross post from http://www.ozgrid.com/forum/showthread.php?t=149129 - just needed a bit of further advice so I thought i'd get some more eyes looking at the issue.

    I have an array formula - =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)),1))

    File attached now.

    'Risk Register Testing' is another sheet in the workbook which contains the data table I want to query, 6.2 is the matching term and 1 is the occurence I wish to retrieve. However, I am getting a #n/a error.

    The data table in 'Risk Register Testing' is constructed through a series of if statement to clean the data and remove blank/erroneous cells.

    When I copy and paste the data into the sheet that contains my array formula and recreate my formula, it works absolutely fine.

    Really puzzled here...

    Also is there anyway to stop the parentheses from disappearing everytime the cell is amended or clicked into? This spreadsheet will go out to a lot of end users who will not know to do the ctrl-shift-enter.

    Any help offered will be greatly appreciated
    Attached Files Attached Files
    Last edited by HSU; 12-21-2010 at 06:04 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Array formula and parentheses

    You might want to attach your file here as well as a lot of people won't want to join OzGrid (can't think why).

    As for your question about the {} the only way to tell Excel it's an array formula is with Ctrl+Shift+Enter so no you can't get round that. How about protecting the worksheet so the formula can't be edited?

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    12-21-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Array formula and parentheses

    Quote Originally Posted by Domski View Post
    You might want to attach your file here as well as a lot of people won't want to join OzGrid (can't think why).

    As for your question about the {} the only way to tell Excel it's an array formula is with Ctrl+Shift+Enter so no you can't get round that. How about protecting the worksheet so the formula can't be edited?

    Dom
    Apologies for that, the file is now attached to the original post.

    Thank you for clearing up the {} issue as well :o)
    Last edited by HSU; 12-21-2010 at 06:05 AM.

  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: Array formula and parentheses

    incidently
    ROW('Risk Register Testing'!AA11:AA85)
    could just be
    ROW(11:85)
    "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

  5. #5
    Registered User
    Join Date
    12-21-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Array formula and parentheses

    Quote Originally Posted by martindwilson View Post
    incidently
    ROW('Risk Register Testing'!AA11:AA85)
    could just be
    ROW(11:85)
    i'm a little confused, how will excel now which worksheet and column to look at? Anything that shortens my formulas is of great interest and importance to me

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

    Re: Array formula and parentheses

    row(a11:a85)
    row(sheet20!z11:sheet20!z85)
    row(11:85)
    all produce the same array ,a list of numbers from 11 through to 85
    it has nothing to do with the sheet they are on

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Array formula and parentheses

    The specific reason that your formula returns #N/A is that you have an #N/A error in the range 'Risk Register Testing'!AA11:AA85 (in AA34). You either need to prevent that at source (change formulas in 'Risk Register Testing'!AA11:AA85) or alter your other formula to ignore #N/A

    In any case your formula won't extract the correct value. The first 6.2 is in row 16 so the SMALL part of the formula returns 16, so this.....

    =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)),1))

    ....becomes

    =INDEX('Risk Register Testing'!AB11:AB85,16)

    the 16th value in the range 'Risk Register Testing'!AB11:AB85 is in 'Risk Register Testing'!AB26, I assume you want the value from 'Risk Register Testing'!AB16. The best way to do that is to change the formula to this

    =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)-ROW('Risk Register Testing'!AA11)+1),1)

    ....or to ignore error values

    =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF(ISNUMBER('Risk Register Testing'!AA11:AA85),IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)-ROW('Risk Register Testing'!AA11)+1)),1))

    Note: I think there is a value in referring to the other worksheet within the ROW function. In the formula above if some rows are added or deleted below or within the range the formula will adjust to the new range, hence it's more robust
    Audere est facere

  8. #8
    Registered User
    Join Date
    12-21-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Array formula and parentheses

    Quote Originally Posted by daddylonglegs View Post
    The specific reason that your formula returns #N/A is that you have an #N/A error in the range 'Risk Register Testing'!AA11:AA85 (in AA34). You either need to prevent that at source (change formulas in 'Risk Register Testing'!AA11:AA85) or alter your other formula to ignore #N/A

    In any case your formula won't extract the correct value. The first 6.2 is in row 16 so the SMALL part of the formula returns 16, so this.....

    =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)),1))

    ....becomes

    =INDEX('Risk Register Testing'!AB11:AB85,16)

    the 16th value in the range 'Risk Register Testing'!AB11:AB85 is in 'Risk Register Testing'!AB26, I assume you want the value from 'Risk Register Testing'!AB16. The best way to do that is to change the formula to this

    =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)-ROW('Risk Register Testing'!AA11)+1),1)

    ....or to ignore error values

    =INDEX('Risk Register Testing'!AB11:AB85,SMALL(IF(ISNUMBER('Risk Register Testing'!AA11:AA85),IF('Risk Register Testing'!AA11:AA85=6.2,ROW('Risk Register Testing'!AA11:AA85)-ROW('Risk Register Testing'!AA11)+1)),1))

    Note: I think there is a value in referring to the other worksheet within the ROW function. In the formula above if some rows are added or deleted below or within the range the formula will adjust to the new range, hence it's more robust
    Thank you for your help DLL.

    I am still a little confused. If I understood correctly, will your formula return the value from the 16th row in the array or the 16th match for my search term denoted here as 6.2?

    I am specifically after an array formula that returns Nth occurences i.e. a Vlookup type affair where I can retrieve the 2nd or 3rd or 4th match and not just the first one.
    Last edited by HSU; 12-21-2010 at 12:32 PM.

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Array formula and parentheses

    HSU - Please don't quote whole posts as per the forum rules:

    12. Don't quote whole posts -- it's just clutter. If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding
    Dom

  10. #10
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Array formula and parentheses

    Yes, the formulas I suggested still return the first match.....and if you change the 1 in the small function to a 2 or 3 or n then it will return the 2nd, 3rd or nth match.

    The point I was making was that your formula would return a value from the wrong row (specifically 10 rows too far down, not necessarily a row where the AA column was 6.2), my suggestions fix that - the second one also allows error values in the range 'Risk Register Testing'!AA11:AA85

  11. #11
    Registered User
    Join Date
    12-21-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Array formula and parentheses

    Ok, I kind of follow you now. For some reason, the formula was pulling up random results if I didnt enter the ctrl+shift+enter parentheses, but it seems to work fine now.

    My final question is, the formula has to be able to handle n number of matches and display them on a grid (which I have created). I don't expect n to be greater than 16, but where I only have 8 matches, the 9th formula in the 9th grid will not find a 9th match and therefore #NUM! error. What is the best way to error handle in this instance?

    In the past I have used an ISERROR approach, but the way I know how to write them, means I have to enter the formula provided twice, once for the error check and then again for the false outcome. Is there a cleaner and simpler way of doing this?
    Last edited by HSU; 12-22-2010 at 06:59 AM.

  12. #12
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Array formula and parentheses

    In Excel 2007 you can use IFERROR to avoid repeating the formula, e.g. to get a blank instead of an error

    =IFERROR(original_formula,"")

  13. #13
    Registered User
    Join Date
    12-21-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Array formula and parentheses

    great! will this work for 2003 users too? I don't think everyone has 2007 in the company yet.

    No need for reply now - answered my own question. Thanks.
    Last edited by HSU; 12-22-2010 at 07:53 AM.

  14. #14
    Registered User
    Join Date
    12-21-2010
    Location
    Kabul, Afghanistan
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Array formula and parentheses

    I have a different question about array formulae and parantheses.

    I'm trying to get each cell in C1:C10 to show how many cells have numbers in the range Ax:A10, where x=ROW(Cx). So instead of putting separate formulae in each cell like this
    C1=COUNT(A1:A10)
    C2=COUNT(A2:A10)
    ...
    C10=COUNT(A10:A10)
    ... I selected the range C1:C10 and just entered this with a CSE at the end:
    =COUNT((A1:A10):A10)

    I didn't get any error message, but I didn't get the expected result either - all C cells now had the exact same number in them: the total number of cells with numbers from A1 to A10 (so it was as if I had entered =COUNT(A1:A10) into all the C cells).

    What am I doing wrong? What would the array formula have to look like in order to express what I want expressed?

    Thanx.

  15. #15
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Array formula and parentheses

    donjoe,

    Welcome to the board.

    Per the forum rules please start your own thread rather than posting questions in someone elses.

    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread.
    Dom

  16. #16
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Array formula and parentheses

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  17. #17
    Registered User
    Join Date
    12-21-2010
    Location
    Kabul, Afghanistan
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Array formula and parentheses

    OK, my bad, will do.

+ 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