Viewing 40 posts - 1 through 40 (of 55 total)
  • VLOOKUP.. argh..!
  • molgrips
    Free Member

    Grr.

    Got a sheet called data definition, contains a list of countries in column B and their ISO codes in C. In another sheet I have a list of a sequence of country codes and I need their names, based on the list in the data definition sheet.

    So I put in =VLOOKUP(C5, ‘Data Definition’!B4:C254, 1) and it does not work. What gives?

    I ask it to look up DE and it returns Algeria. Wtf?

    STATO
    Free Member

    You are trying to find the countries (B) by looking for the ISO (C)? Dont think you can do it that way?

    A drawback of the VLOOKUP function is that it can only look up values in the leftmost column of a table.

    miketually
    Free Member

    Quick guess: is range lookup allowed by default? So it’s assuming the list is alphabetical and it’s not and so it throwing up an out of sequence result? Chuck a false in there as a fourth argument.

    Edit: Actually, what stato said.

    Andy_B
    Full Member

    change your last argument from 1 to 0

    edit: actually add a 4th argument = 0

    perchypanther
    Free Member

    You’re trying to return a result from the first column in the lookup table which doesn’t work. The initial lookup in C5 needs to be the same as the matching value in the first column of your reference table ‘Data Definition’!B4:C254

    The result you’re looking to return needs to be in the second
    column and the formula would be :

    =vlookup(c5,’Data Definition’!B4:C254,2,false)

    this will look at what is in C5, find the first matching entry in the lookup table and return the value to the right of the matched entry in the lookup table. i.e in Column 2

    Cougar
    Full Member

    You need to reorder the columns. Swap B and C over.

    molgrips
    Free Member

    Looks like it only looks up from left to right.

    So the data definition was Country Name/ISO code. I copied it and changed it to ISO code/Country Name and it worked.

    BUT

    When I tried to autopopulate the rest of the rows, it incremented ALL the row references, including the ones in the reference range!

    So I wanted this:

    =VLOOKUP(C5, G5:H255, 2)
    =VLOOKUP(C6, G5:H255, 2)
    =VLOOKUP(C7, G5:H255, 2)

    and I got this:

    =VLOOKUP(C5, G5:H255, 2)
    =VLOOKUP(C6, G6:H256, 2)
    =VLOOKUP(C7, G7:H257, 2)

    Honestly. FFS.

    Stoner
    Free Member

    if you are unable to change the structure of the Data Definition table to put the ISO in the left most column, you can use MATCH and OFFSET instead

    e.g.

    =offset( ‘Data Definition’!$b$4, match(C5, ‘Data Definition’!$B$4:$C$254)-1, 0, 1, 1)

    STATO
    Free Member

    =VLOOKUP(C5, G$5:H$255, 2)

    How much do you earn an hour? payment by paypal please 😀

    thestabiliser
    Free Member

    =VLOOKUP(C5, G:H, 2)

    perchypanther
    Free Member

    You are using relative references in your lookup table e.g. C5 rather than absolutes e.g. $C$5

    add a $ before the row and column refs in your original formula and recopy. f4 is your friend here.

    It’ll work then.

    Andy_B
    Full Member

    just remove the numbers so that your 2nd argument reads G:H

    jate
    Free Member

    In true STW, rather than answering your question I would suggest doing something different……
    VLOOKUP isn’t a great function imho. Far better and more flexible is to use a combination of INDEX/MATCH or OFFSET/MATCH.

    molgrips
    Free Member

    Thanks. Sorted.

    Not come across that $ thing before. How on earth can C5 be a relative reference? Confused.

    perchypanther
    Free Member

    How on earth can C5 be a relative reference? Confused.

    It’s a hangover from the earliest versions which has been retained as it is a useful feature for many users.

    Unless you instruct it otherwise by using the $, If you put =c5 in cell d6 Excel actually reads the formula internally as =row-1,column-1 as that was how the first versions worked. You can alter the cell reference structure to R1C1 format if it makes it easier.

    Sundayjumper
    Full Member

    With the original data set:

    =INDEX(‘Data Definition’!B:B,MATCH(C5,’Data Definition’!C:C,0))

    I seemingly do this kind of formula a gazillion times a day…. yay me.

    reggiegasket
    Free Member

    Just use MATCH and INDEX. Much more flexible.

    [beaten to it…]

    jambalaya
    Free Member

    Not come across that $ thing before. How on earth can C5 be a relative reference? Confused.

    Really ? Without the $ it is always relative and always changes when you copy paste. That’s just how Excel has always worked.

    The thing that always bugged me with lookup is having to have the values sorted

    Stoner
    Free Member

    The thing that always bugged me with lookup is having to have the values sorted

    doesnt need to be sorted
    Use FALSE for match type to make sure it brings back exact matches though

    molgrips
    Free Member

    C5 is always an absolute reference. I guess the $ must mean it’s immutable.

    EDIT I think I see what PP is on about. It’s an absolute reference derived by relative means. Pfft.

    mefty
    Free Member

    Using Range Names for Table of Data would also avoid the need to use $ signs, which really are primary level Excel. Good practice too.

    STATO
    Free Member

    Using Range Names for Table of Data would also avoid the need to use $ signs, which really are primary level Excel. Good practice too.

    Range names are great but its much harder to quickly sense check large sheets with multiple calcs without checking every single range is still correct after someone else who might not be as proficient has been messing with the sheet. At least with bare references you can check consistency or just re-apply as a Quality check.

    dannyh
    Free Member

    VLOOKUP is for pussies. INDEX(MATCH) is where the cool kids hang out.

    Stoner
    Free Member

    Named ranges are a ballache for model auditing.
    I never use them, and I when Im coaching I generally advise to avoid them in favour of better model design.

    RobHilton
    Free Member

    Dynamic ranges FTW!

    Stoner
    Free Member

    Dynamic ranges for graphing is permitted 🙂

    RobHilton
    Free Member

    *for everything!! :mrgreen:

    thepurist
    Full Member

    If you really want to baffle anyone use array formulae on dynamic ranges, that’ll kill someone’s afternoon.

    Oh and if you’re using lookup or match remember the error handling, nothing worse than all those #NAs

    molgrips
    Free Member

    Using Range Names for Table of Data would also avoid the need to use $ signs, which really are primary level Excel.

    You lot know Excel isn’t my job, don’t you?

    RobHilton
    Free Member

    I do love how devs look down on Excel, but when it comes time to use it they can’t get their massive heads around it :mrgreen:

    molgrips
    Free Member

    I don’t look down on it. I use it for its job. Just one of the huge array of tools, skills and technologies in my massive head 🙂

    Cougar
    Full Member

    You lot know Excel isn’t my job, don’t you?

    And you don’t know about $ fixing? Career change?

    (I found out about it literally yesterday, so am of course an expert.)

    mefty
    Free Member

    You lot know Excel isn’t my job, don’t you?

    I had assumed you were unemployed as your occupation appears to be posting on here – Excel is a life skill now, my daughter was taught about $ fixing at primary school hence my comment.

    miketually
    Free Member

    I’m pretty sure I was taught absolute referencing in year 8 doing CLAIT 🙂

    njee20
    Free Member

    just remove the numbers so that your 2nd argument reads G:H

    Don’t do this. VLookups use quite a lot of memory, and making the references >1million rows does little to help!

    molgrips
    Free Member

    Excel is a life skill now, my daughter was taught about $ fixing at primary school hence my comment.

    You know what else is a life skill? Google, and posting on the internet to find answers 🙂

    mefty
    Free Member

    On the more important point about range names, I tend to use pretty obvious names so it is self evident where I am picking up from. On the odd occassion when my stuff has been audited, they have found it easy to follow. The other practice that I think is good for vlookups is to use the COLUMNS function to count across. This means if you add a column of data it will automatically adjust and your calcs aren’t thrown out.

    EDIT: I also have a table of Range Names on the front sheet that is updated when the sheet is opened.

    molgrips
    Free Member

    All good tips thanks folks. Will come in handy in the future, but in this case all I wanted was a one-time list of strings to paste into something so long term maintenance isn’t an issue.

    Re education though – I wasn’t taught Excel of course. In school we had a few hours on some BBC word processor that wasn’t WYSIWYG, and at 6th form college in Computer Studies we actually did learn about punched cards. Most of my contemporaries are the same. So we look like bumbling oafs with office software as we design enterprise systems.

    A friend of my wife’s struggling to manage her small business without using any IT whatsoever because she has no idea what to do, doesn’t even own a computer. Even though she’s younger than us – and is degree educated. When Office skills are as fundamental as arithmetic and reading, we’re going to look a bit rubbish if we aren’t careful.

    When you look at old people fumbling with technology, and you wonder if that will one day be you – well this is how it starts.

    RobHilton
    Free Member

    molgrips – Member
    I don’t look down on it. I use it for its job.

    I’ll bet you do, actually – whereas *way* too many people use it for absolutely everything.

    crazy-legs
    Full Member

    I’ll bet you do, actually – whereas *way* too many people use it for absolutely everything

    I’ll counter that with way too many people can only use about 4 functions on it and then it comes to getting some meaningful data out of it and they’re going through it manually with a calculator in one hand.

    I went on an intermediate Excel course through work and it was very interesting – partly because I learnt some new stuff but partly because it was eye opening seeing how little most people knew about it. All the examples the teacher used were from real-time scenarios where people were manually trawling through data that Excel could have calculated in seconds.

Viewing 40 posts - 1 through 40 (of 55 total)

The topic ‘VLOOKUP.. argh..!’ is closed to new replies.