+ Reply to Thread
Results 1 to 16 of 16

Getting value from next-highest 'header' row

  1. #1
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Getting value from next-highest 'header' row

    Hi all,

    I have a worksheet that contains a number of rows. [Thank you, Captain Obvious!] These rows are logically grouped to represent a series of "items", with each item having one or more rows (with a "header" row at the top). The rows for a particular item represent different types of information about that item, and therefore make use of different formulas based on the row type. Due to the relative complexity of the formulas in these rows, I am creating a series of row "templates" from which I can copy and paste every time I want to create a new item or add rows to an item. As such, I am trying to avoid direct cell references to different rows, as these would easily get messed up during cut and paste. Instead, I am trying to limit myself to various lookup functions (e.g. OFFSET, MATCH, etc...) that will work regardless of where a row is added.

    In order to accomplish this I am using a "key" column to group all rows for a particular item together. Until now I have had to type in the key value for every row for a particular item. What I would like to do is to only have to type the key value in the header row, and have a formula populate the key value in all subsequent rows ... until a new header row is reached, at which point the new key value will be used. Take a look at the following example:

    a) Item Header row containing key value in column A and a header "flag" in column B
    b) Item Detail row containing key lookup formula in column A
    b) Item Detail row containing key lookup formula in column A
    b) Item Detail row containing key lookup formula in column A
    > Blank separator row
    b) Item Detail row containing key lookup formula in column A
    b) Item Detail row containing key lookup formula in column A
    > Blank separator row
    b) Item Detail row containing key lookup formula in column A
    b) Item Detail row containing key lookup formula in column A
    > Blank separator row
    c) Item Header row containing key value in column A and a header "flag" in column B
    d) Item Detail row containing key lookup formula in column A
    d) Item Detail row containing key lookup formula in column A
    > Blank separator row
    d) Item Detail row containing key lookup formula in column A
    > Blank separator row
    e) Item Header row containing key value in column A and a header "flag" in column B
    f) Item Detail row containing key lookup formula in column A
    f) Item Detail row containing key lookup formula in column A

    In the above:

    - column A in all "b" rows should lookup the key value in column A of row "a".
    - column A in all "d" rows should lookup the key value in column A of row "c".
    - column A in all "f" rows should lookup the key value in column A of row "e".

    Can anyone suggest how I can accomplish this? I don't want to use direct references between rows. I would like some formula that will fetch the value from column A in the first row above the current row that contains the "flag" in column B.

    I appreciate any help you can offer!

    Thanks,
    Greg
    Last edited by gurtz; 01-30-2009 at 08:13 AM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Getting value from next-highest 'header' row

    It'd be easier if we see an actual sample sheet attached here.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Getting value from next-highest 'header' row

    Thanks for the reply.

    Please see attached.

    Greg
    Attached Files Attached Files

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Getting value from next-highest 'header' row

    Are you trying to automatically populate the titles in Column A where the change occurs? Not following?

    If you are manually typing those in, then you can use this formula in A3 copied down to A9, then re-inserted in A11 and copied down, etc:

    Please Login or Register  to view this content.
    confirmed with CTRL+SHIFT+ENTER not just ENTER. You will see { } brackets appear

  5. #5
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Getting value from next-highest 'header' row

    Using the example worksheet above, I am looking for a generic formula for the yellow cells to produce the following result:

    - cells A3, A5, A6, and A8 should contain "ITEM_KEY_1"
    - cells A11, A12, A13, and A15 should contain "ITEM_KEY_2"
    - cells A18, A19, and A21 should contain "ITEM_KEY_3"

    Does that make sense?

    I will have to study your formula in more detail when I have an opportunity later today. It's a bit beyond my current level of expertise.

    Thanks,
    Greg

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Getting value from next-highest 'header' row

    Then my formula as prescribed above should do that. Give it a try and let me know.

  7. #7
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Getting value from next-highest 'header' row

    Hi NBVC,

    I took some time this evening to try and work this out, but I'm stuck. I tried to use your formula, but I keep getting some sort of error. Can you clarify how this is supposed to work?

    Thanks,
    Greg

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

    Re: Getting value from next-highest 'header' row

    well i've had a look and
    the phrase "as clear as mud" springs to mind!

  9. #9
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Getting value from next-highest 'header' row

    Hi NBVC,

    It works!!!

    I took another look and now realize I neglected to follow your bolded instructions to use Ctrl-Shirt-Enter to confirm the formula. Just this morning I read something about array functions (which are new to me) and remembered seeing your comment. When I enter the formula as an array, it works!

    Thanks so much for all the help!

    Greg

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Getting value from next-highest 'header' row

    NBVC, I don't think you actually need an array here... the following would work:

    Please Login or Register  to view this content.

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Getting value from next-highest 'header' row

    True.... where there is a will there are many ways...

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Getting value from next-highest 'header' row

    Quote Originally Posted by NBVC
    where there is a will there are many ways...
    ...and the one without the array is invariably quicker

  13. #13
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Getting value from next-highest 'header' row

    Hi DonkeyOte,

    Thanks for your reply. That's very helpful!

    I tried your formula, and it works, however, I'm struggling to understand it. Would you mind telling me (in English :-) what the following part of your formula is doing?

    Please Login or Register  to view this content.
    Thanks much,
    Greg

  14. #14
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Getting value from next-highest 'header' row

    LOOKUP(2,1/($A$1:$A2<>""),$A$1:$A2)
    That Lookup() formula will find the last entry that matches the condition in the denominator of the Lookup Array argument (ie. the 2nd argument of the function).

    If you select the cell with the formula and go to Tools|Formula Auditing|Evaluate Formula and click Evaluate to step through the way the formula is evaluated, you will see what is going on.

    The denominator, when evaluated, creates an array of TRUEs and FALSEs depending on if the condition is met or not in each element of the array. The 1/denominator will then create an array of 1's or #DIV/0 errros because 1/TRUE is the same as 1/1 which =1 and 1/FALSE is the same as 1/0 which results in an error....

    Now the next thing for the Lookup() function to do is look for a 2 in that resultant array... It can't find one and the function looks for the last entry in the array that is smaller than or equal to the 2.. ie. the last 1 in the array is targeted and that postion is returned... then the corresponding item from the lookup vector (the 3rd argument) is extracted.

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Getting value from next-highest 'header' row

    I would add the following...

    Please Login or Register  to view this content.
    LOOKUP will look for items of the same data type as the lookup_value (aka criteria)... so if your lookup vector is evaluated as follows:

    Please Login or Register  to view this content.
    and your criteria is 2 the #DIV/0! are ignored as they are not numbers... this is why LOOKUP is so handy.... more often that not formulae referencing error values in turn generate an error result... not so LOOKUP... so by coercing the values you want to ignore to become an Error (#DIV/0!) and the ones you want to keep to a number (1) you filter your records....

    Given the MAX value you can generate in your array of values is going to be 1 by setting the lookup_value to 2 you will always find the last instance of 1 in the range.... it could be 1.000001 (ie any value > 1) but 2 obviously is easier to follow so is the standard.

    I'm not an expert on this so I'll happily stand corrected.
    Last edited by DonkeyOte; 01-29-2009 at 11:30 AM.

  16. #16
    Registered User
    Join Date
    01-28-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Getting value from next-highest 'header' row

    Hi all,

    Thanks so much for all the help. I appreciate it!

    Greg

+ 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