VLOOKUP.. argh..!
 

[Closed] VLOOKUP.. argh..!

54 Posts
18 Users
0 Reactions
118 Views
Posts: 91113
Free Member
Topic starter
 

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?


 
Posted : 22/11/2016 4:02 pm
Posts: 0
Free Member
 

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

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


 
Posted : 22/11/2016 4:06 pm
Posts: 11937
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.


 
Posted : 22/11/2016 4:06 pm
Posts: 515
Full Member
 

change your last argument from 1 to 0

edit: actually add a 4th argument = 0


 
Posted : 22/11/2016 4:07 pm
Posts: 17304
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


 
Posted : 22/11/2016 4:07 pm
Posts: 77753
Free Member
 

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


 
Posted : 22/11/2016 4:09 pm
Posts: 91113
Free Member
Topic starter
 

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.


 
Posted : 22/11/2016 4:10 pm
Posts: 36
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)


 
Posted : 22/11/2016 4:12 pm
Posts: 0
Free Member
 

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

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


 
Posted : 22/11/2016 4:12 pm
Posts: 8889
Free Member
 

=VLOOKUP(C5, G:H, 2)


 
Posted : 22/11/2016 4:12 pm
Posts: 17304
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.


 
Posted : 22/11/2016 4:12 pm
Posts: 515
Full Member
 

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


 
Posted : 22/11/2016 4:13 pm
 jate
Posts: 0
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.


 
Posted : 22/11/2016 4:17 pm
Posts: 91113
Free Member
Topic starter
 

Thanks. Sorted.

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


 
Posted : 22/11/2016 4:17 pm
Posts: 17304
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 [b]=row-1,column-1[/b] as that was how the first versions worked. You can alter the cell reference structure to R1C1 format if it makes it easier.


 
Posted : 22/11/2016 4:20 pm
Posts: 0
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.


 
Posted : 22/11/2016 4:43 pm
Posts: 6332
Free Member
 

Just use MATCH and INDEX. Much more flexible.

[beaten to it...]


 
Posted : 22/11/2016 4:43 pm
Posts: 0
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


 
Posted : 22/11/2016 4:50 pm
Posts: 36
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


 
Posted : 22/11/2016 4:54 pm
Posts: 91113
Free Member
Topic starter
 

C5 is always an absolute [i]reference[/i]. 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.


 
Posted : 22/11/2016 4:54 pm
Posts: 7270
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.


 
Posted : 22/11/2016 5:17 pm
Posts: 0
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.


 
Posted : 22/11/2016 5:23 pm
Posts: 0
Free Member
 

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


 
Posted : 22/11/2016 6:09 pm
Posts: 36
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.


 
Posted : 22/11/2016 6:11 pm
Posts: 1781
Free Member
 

Dynamic ranges FTW!


 
Posted : 22/11/2016 6:19 pm
Posts: 36
Free Member
 

Dynamic ranges for graphing is permitted 🙂


 
Posted : 22/11/2016 6:19 pm
Posts: 1781
Free Member
 

*for everything!! :mrgreen:


 
Posted : 22/11/2016 6:37 pm
Posts: 10872
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


 
Posted : 22/11/2016 6:40 pm
Posts: 91113
Free Member
Topic starter
 

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?


 
Posted : 22/11/2016 6:55 pm
Posts: 1781
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:


 
Posted : 22/11/2016 7:07 pm
Posts: 91113
Free Member
Topic starter
 

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 🙂


 
Posted : 22/11/2016 7:08 pm
Posts: 77753
Free 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.)


 
Posted : 22/11/2016 7:37 pm
Posts: 7270
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.


 
Posted : 22/11/2016 8:27 pm
Posts: 11937
Free Member
 

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


 
Posted : 22/11/2016 8:37 pm
Posts: 71
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!


 
Posted : 22/11/2016 9:09 pm
Posts: 91113
Free Member
Topic starter
 

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 🙂


 
Posted : 22/11/2016 9:15 pm
Posts: 7270
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.


 
Posted : 22/11/2016 10:24 pm
Posts: 91113
Free Member
Topic starter
 

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.


 
Posted : 22/11/2016 11:13 pm
Posts: 1781
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 [i]everything[/i].


 
Posted : 23/11/2016 12:22 am
Posts: 20410
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.


 
Posted : 23/11/2016 7:02 am
Posts: 91113
Free Member
Topic starter
 

whereas *way* too many people use it for absolutely everything.

A large part of my job is providing the enterprise replacement for the traditional big pile of spreadsheets, so I'd agree with that 🙂 Generally some hero has hand-crafted these things and no-one knows what's inside them or why they are like they are.


 
Posted : 23/11/2016 8:28 am
Posts: 0
Free Member
 

The problem with excel is its designed for people who know what they want to do with it.

As soon as google work out a way to combine their search engine with a spreadsheet Microsoft will die. Imagine just being able to describe what you want to be done, and getting the response with additional info about what it has (and has not) done.


 
Posted : 23/11/2016 8:28 am
Posts: 11937
Free Member
 

Some really big financial decisions were found to be being made using 'data' from really shonky spreadsheets. It's scary.

There are loads of tasks that I complete quickly using spreadsheets and some algorithmic thinking. Watching colleagues stumble through the same stuff manually is embarrassing.


 
Posted : 23/11/2016 11:37 am
Posts: 515
Full Member
 

should we let him in on the F4 secret?


 
Posted : 23/11/2016 11:57 am
Posts: 91113
Free Member
Topic starter
 

Sorry for being stupider than a primary school kid, my education has been very poor.. but...

What do you all think this does in a cell?

=IF(ISBLANK(F6), "", CONCAT("Check rule ", F6))

I want it to make the value of the cell 'Check rule X' where X is the contents of the cell in F, *unless* that cell is blank, in which case make the cell blank.

However it doesn't work - with the blank cells in F I get 'Check rule '

What am I missing?


 
Posted : 23/11/2016 12:09 pm
Posts: 17304
Free Member
 

Try this. Worked for me.

=IF(ISBLANK(F6), "", CONCATENATE("Check rule ", F6))


 
Posted : 23/11/2016 12:19 pm
Posts: 91113
Free Member
Topic starter
 

Fffffuuuu....

So I click on the cell F6, clear contents, and it works. There are invisible characters in the cells.

AARGH

EDIT and if I use TRIM() it stops working altogether, even if I also clear contents.


 
Posted : 23/11/2016 12:22 pm
Posts: 17304
Free Member
 

Probably a zero in the cell and excel is set to not display zero values.

Not the same as blank.


 
Posted : 23/11/2016 12:24 pm
Posts: 91113
Free Member
Topic starter
 

Nope.


 
Posted : 23/11/2016 12:40 pm
Posts: 17304
Free Member
 

Pilot error then. 😉


 
Posted : 23/11/2016 12:41 pm
Posts: 36
Free Member
 

try CLEAN instead of TRIM


 
Posted : 23/11/2016 12:43 pm
Posts: 17304
Free Member
 

I'd have approached it from the other end TBH

It's always easier to make a formula conditional on a positive result e.g =if (f6>0..... than a negative result e.g =IFBlank(f6....

I'd have done the formula like this. (assumes a numerical value in f6)

=if(f6>0,CONCATENATE("check Rule ",f6),"")

This way it'll always default to blank unless the positive condition is fulfilled.

Edit, this will work for text values of f6 also but will catch non displaying zeros


 
Posted : 23/11/2016 12:46 pm
Posts: 0
Full Member
 

[quote="miketually"]Some really big financial decisions were found to be being made using 'data' from really shonky spreadsheets. It's scary.
Are you looking at me ? 😀

I can confirm that "scary" is quite an understatement... I'm looking at things in the £billions here.


 
Posted : 23/11/2016 1:04 pm
Posts: 91113
Free Member
Topic starter
 

Thanks.

Gave up in the end - much as I want to find out what's going on, I have code to write. Cleared out the cells by hand.


 
Posted : 23/11/2016 1:09 pm
Posts: 0
Full Member
 

[quote="Rob Hilton"]...whereas *way* too many people use it for absolutely everything.

Using Excel as a word processor.
Using Word as a spreadsheet.

Once, when I had asked for detail of some hours from timesheets, the person took screengrabs from Excel and pasted them into Word as images, then sent me that. WTF ???


 
Posted : 23/11/2016 1:11 pm