View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Pete
 
Posts: n/a
Default Only 8 if A5=this, then B4=that. How can I put in more?

A table is simply two or more columns of data, as opposed to a list
which is just a single column. So a table of your data would look like:

1K 51126
2AC 36320
OAP 49003
3AC 36316
9CH 45284
1DB 318
6AC 53570
149 1045

In Sloth's posting, he was assuming that this table would be typed in
cells from A1 to B8, although you could put this table anywhere that is
suitable in your worksheet - if you do, you would need to change the
range A1:B8 in his formula to suit the cells where your table is
located.

Using a table like this, your long formula with all the IF statements
can be replaced with the VLOOKUP formula he supplied, i.e.:

=VLOOKUP(F5,A1:B8,2,FALSE)

What this does is to compare the value in cell F5 with the values in
the first column of the table, i.e. in column A, and if it finds an
exact match then it will return the corresponding value from column 2
of that table, i.e. from column B. This is exactly the same as having 8
IF statements. A further advantage of using Vlookup, though, is that
you can have many more entries in your table. Imagine you have 20
values of A and corresponding values in B, occupying A1 to B20 - all
you need to do is make a slight amendment to the formula as follows:

=VLOOKUP(F5,A1:B20,2,FALSE)

and this will accommodate the extra conditions.

If the value in F5 does not exist in the column of values in your
table, however, then the function will return #N/A to indicate this
error. Sloth's final formula helps you to prevent this from happening -
basically it means "If the lookup function will return an error, then
just put "" in the cell, otherwise let the lookup function return its
value".

Hope this helps to explain things a bit more.

Pete