+ Reply to Thread
Results 1 to 6 of 6

horizontal lookup/fill

  1. #1
    Registered User
    Join Date
    07-24-2009
    Location
    Los Angeles, US
    MS-Off Ver
    Excel 2003
    Posts
    7

    horizontal lookup/fill

    Hi,
    below is an example of an array on a sheet:

    A B C D
    bob 1 2 3
    joe 7 8 9

    right now i'm using vlookup in a second sheet to lookup "bob" and the corresponding values in the columns from the first sheet. ex: =vlookup($A1,sheet1!$A:$D,2,0), A1="bob" in the second sheet.

    i want to be able to drag that formula across to column D and have the column index go up sequentially(2, 3, 4) so that i get the same values as the first line in the first sheet. is vlookup able to do this? if not, is there another formula i can use? is there a symbol/formula i can enter in place of the row index that will move it sequentially? seems like i've been using vlookup for far too long and i need to venture out to some formulas that might be more efficient. any suggestion is appreciated.

    thanks.

  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: horizontal lookup/fill question

    replace the column number with
    COLUMNS($A$1:A1) (thats = to 1)
    columns simply counts the cols in a given range when dragged across it will change to
    COLUMNS($A$1:B1) Ie 2
    COLUMNS($A$1:C1) ie 3
    so in your case starting from 2 use
    COLUMNS($A$1:B1)

    vlookup($A1,sheet1!$A:$D,COLUMNS($A$1:B1),0)
    note you dont have to use the columns you're in

    COLUMNS($BA$1:BA1) for example would also = 1 no matter where you use it on the sheet
    you can also do the same with rows() on dragging down
    rows($A$1:A1) =1
    changes to
    rows($A$1:A2) =2
    Last edited by martindwilson; 10-28-2009 at 07:54 PM.
    "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 Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Re: horizontal lookup/fill question

    pfchang,

    try this:

    =vlookup($A1,sheet1!$A:$D,COLUMN(),0)

    However, beware of the COLUMN() function, it returns the column number where the formula is typed and hence is not a relative reference. If you are using it in other situations it would be wise to check what it is returning before inserting into a larger formula such as the one above.

  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: horizontal lookup/fill question

    trouble with column() is you have to adjust it
    so if you are in col g it will return 7 so to get 2 you have to use column()-5
    a bit of a pain really and would put the formula out if you inserted a column in the wrong place

  5. #5
    Forum Contributor
    Join Date
    08-14-2008
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    103

    Re: horizontal lookup/fill question

    Quote Originally Posted by martindwilson View Post
    trouble with column() is you have to adjust it
    so if you are in col g it will return 7 so to get 2 you have to use column()-5
    a bit of a pain really and would put the formula out if you inserted a column in the wrong place
    martindwilson,
    Absolutely, I agree! Hence the warning at the bottom of my post.

    pfchang,
    I have to defer to the Forum Guru on this, his solution is clearly more robust than mine. But now we have both learnt something

  6. #6
    Registered User
    Join Date
    07-24-2009
    Location
    Los Angeles, US
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: horizontal lookup/fill

    Awesome! Thanks so much! that cuts down a big chuck of time.

+ 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