Saturday, February 20, 2010

Excel - VLookup How To

How To: Use Excel's powerful VLookup feature to make cross-table / cross-lookups. This is a comprehensive tutorial, showing best practices on all aspects of a VLookup and it relies heavily on named-ranges. These instructions were written with Office 2007. Excepting for minor menu changes, these same instructions work with any version of Excel.

Synopsis:
=Vlookup(what you are looking for, where, which column, exact-match=False)
=IfError(Vlookup(what, where, column, false),"Not Found")

Steps:
1. Create table of values to lookup in a separate sheet.
2. Range-name table (minus header row)
3. Build VLookup, selecting base-1 column name


Contents:
  • VLookup - Name the Range
  • Parameters
  • Selecting the Range - the "trick"
  • Improved VLookup using IfError
  • Fixing Range Names
  • Performance Concerns
  • Dirty (Numeric) Data
  • Non-exact searches (within a range of values)


VLookup Introduction:

In Excel, a VLookup allows your sheet to "vertically lookup another value" in another sheet. This example shows an Account Number table, where you want to retrieve the description and current-year budget and place the results in your current sheet.


With the VLookup, your sheet can have a typed Account Number (illustrated, in Cell B5), and other values from the lookup table, such as the description and budget-amounts, can be returned in a cross-lookup. Usually, the account (lookup) table is a separate spreadsheet but it can be in the same sheet or on another workbook tab.

If data in the lookup table changes, for example, assume the dollared budget amount changes, the new sheet picks up the new value automatically. With this, one group of people can maintain the account list, and all other linked sheets will see the most current values.



VLookup Setup:


In a (usually) separate sheet, set up a list of values to lookup. This can be account codes, employee numbers, part-numbers, people names, etc.


1. Open a new, blank spreadsheet.
2. Load or type account information, where:
  • The first column must contain a unique value (the Key) for each record.
  • No duplicate entries are allowed in the first column.
  • Any number of columns can follow the first (Description, budget, etc.)
  • Column headings are recommended, but not required.
  • The list *must* be sorted alphabetically/Numerically by the first column. (Technically, it 'should be' sorted if you are using "exact-matching"; it 'must' be sorted if not exact-matching. Sorting is always recommended.)
Your list can contain hundreds to thousands of entries and the keys do not have to be numeric.

Name the Range:

Although you do not have to name the range, it is recommended. Follow these steps:

3. Once typed, highlight the data (all rows, all columns, *not including* the Header)

a. 'Other-mouse-click' the highlighted cells, choose "Name a Range"; name the range a meaningful name, such as "MyAccounts".

a1. Alternately, click in the area directly above column A and type the range-name there.


a2. Alternate-Alternately: Click top Menu Formulas, Define Name


The Range-name makes future work easier, see below for more information.

b. Save the entire sheet to disk, giving it a meaningful name such as "Accounts.xlsx" or "FY10Accounts".

Once saved, leave the sheet open while building the Vlookup formulas. In the future, this sheet can be opened or closed and it will still work properly -- but if it is already opened, lookups are faster.


Using VLookups in your Sheet


4. In a new sheet (File, New, Blank workbook), move to an arbitrary cell (B5).
5. Literally, type an account-number to look up: For example, "2356"


6. In Cell C5, begin the lookup formula by typing "=VLookup(" (open parenthesis).

Note the popup help:


Click illustration for larger view; click right-x to return.

a. For the first parameter, after the parenthesis, click cell B5 (2356). This is the value you are trying to look up.

* Type a Comma (,) to move to the next parameter.

b. While still in the midst of the formula's second parameter, take the mouse and click anywhere in the Account look up sheet. Click one time to activate the sheet, a second time to select a cell. Select any cell in the sheet.

If the sheet is covered or otherwise not visible, click the top Excel menu View, Switch Windows.)

(Because you are using a range-name, you do not need to highlight all the data, just click anywhere in the sheet to set the sheet's name. )

In my example, the bottom tab was renamed to "MasterAccounts"; if you did not rename the sheet, it will show as "Sheet1", which is acceptable. Once selected, the second parameter in the Vlookup formula will look like one of these, where the "$B$7" is unimportant:

=Vlookup(B5,[Accounts.xlsx]MasterAccounts!$B$7 or
=Vlookup(B5, [Accounts.xlsx]Sheet1!$B$7


c. Here is the trick:

While still building the second parameter, backspace over the newly-selected address, deleting the "$B$7" (or what ever address you selected) -- up until, but not including the exclamation (also called a "bang").

d. Replace the $B$7 (or what ever) with the Ranged-name "MyAccounts":

After backspacing and typing the RangeName "MyAccounts":
=Vlookup
(B5,[Accounts.xlsx]MasterAccounts!MyAccounts


or

=Vlookup(B5, [Accounts.xlsx]Sheet1!MyAccounts


e. Type a comma (,) to continue the formula.

The next parameter is column-data you want returned into the sheet. For the current VLookup cell, this will be the description (column 2). Type a "2", followed by another comma:


f. Finally, type a comma-",False", which tells the formula it must find an Exact-match in the lookup table; this is the most common option.

g. Close the parenthesis) and press Enter. The completed formula:

=Vlookup(B5,[Accounts.xlsx]MasterAccounts!
MyAccounts,2,False)


=Vlookup(B5, [Accounts.xlsx]Sheet1! MyAccounts,2,False)

Results: The Description for account code 2356 ("Networking") is returned.


Lookup another Column in the same Table

In cell D5, one cell to the right, build another VLookup formula, returning the budget amount:

=VLookup (B5,Accounts.xlsx!MyAccounts,3,False)

where:
  • Accounts.xlsx is the name of the sheet
  • "MyAccounts" is the name of the named-range
  • "3" returns the budget from the third column
  • "False" means find an exact match
Cells C5 and D5 (the Vlookup formulas) can be copied and filled down as you would any other Excel formula.


Improved VLookup Formula:


There is a possibility the Vlookup will not find a given account-code; usually because of a mis-keyed value. Test this now by doing the following:

a. In the original cell B5 ("2356"), change the account code to a non-existent account ("2000"). Results: The Vlookup formulas return "#N/A" (Value not found).

Improve the Formula using IFError:

b. Cosmetically, this can be improved with this formula in Cell C5 (all on one line):
IfError(VLookup(B5,Accounts.xlsx! MyAccounts,2,False),"Not Found")

c. In D5, use this formula (note the double-quotes ""):
IfError(VLookup(B5,Accounts.xlsx! MyAccounts,3,False),"")

(Click illustration for larger view, Back to return)

where:
  • =ifError says if "any part of the included formula generates any kind of error (such as a #N/A"), put a different value in the cell. Otherwise, use the original value.
  • Do not use an equal-sign in front of the VLookup clause
  • If an error was found, the formula returns the literal text "Not Found". The second VLookup was changed to return a null (empty) string (quote-quote) if there was an error.
  • In many formulas, the error value often is set to zero (0) instead of "Not Found".

Possible Errors:
  • #N/A (#NA) - An exact match was not found in the lookup table.
  • #N/A The lookup cell address may have shifted or changed, confirm the first parameter is pointing at the value you want to lookup.
  • #Name? - An incorrect or misspelled RangeName (aka "MyAccounts") or the range-name does not exist.

Range-Name Issues:



If you choose not to use a range name in the VLookup, you will have to use a cell-range.

=Vlookup
(B5,[Accounts.xlsx]MasterAccounts!$A3:D13
...

These are inherently fragile. If new values are inserted into the lookup table while your original sheet is closed, the lookups will not see the change and the wrong range will be selected, often resulting in "#NA" values.

With explicit addresses (A3:D13), the range may or may not expand when new rows are inserted into the table, depending on which linked sheets were opened at the time. Compare this to a range-named table, where inserted records automatically expand the range-name. In other words, explicit addresses (A3:D13) are risky.

However, with either the RangeName or Explicit examples, newly-inserted records at the top-most or bottom-most records will not expand the range-names correctly and your VLookups will have sporadic failures when they are near these areas.


Confirming an existing Range-Name:

When inserting records on the top-most or bottom-most rows, confirm the range with one of these methods:

Method 1:

Click the down-doodad right above column A, choose the Range-name "MyAccounts". Excel will highlight the cells. Confirm the highlight encompasses all rows and columns. See below if you need to change.


Method 2:

Use this method to check and, if needed, to change the selected range in the Range-name:

In Excel 2007's ribbon menu, choose "Formulas", Name Manager or press Control-F3.
Confirm the range-name cell address (e.g. $A$3:$D$13). The dollar-signs are important for reasons not described here. To change the range-values, click the red-arrow and re-highlight the table. This example shows a sheet with other range-names:


(Click for a larger view, Back to return)

As an aside, you can see all linked sheets (from your main sheet, not from the Accounts Sheet) by selecting the top-menu Data, Edit Links; "Accounts.xlsx" will show as a linked sheet. Both sheets can be saved as a 'workspace' using "View, Save Workspace". Instead of an xlsx, it will save as an "xlw" (Workspace); both sheets will open simultaneously.

Other Range Names

In the lookup-table sheet, where the MyAccounts range lives, you can have other sections devoted to other lookup values. For example, there might be a Department Lookup table, CategoryCodes, Employee lookup, etc. All can live in the same sheet and all will work well if you use Range Names.

Performance Concerns

Vlookups are somewhat expensive in CPU processing. If your sheet has thousands of lookups, the performance of the sheet will be slow. Consider the following to improve the speed:
  • Open the lookup sheet *before* opening your main sheet.
  • On really large sheets, set manual re-calculation: Menu: Formulas, Calculation Options, Manual. Understand the implications before doing this.
  • The lookup sheet can be closed and the formulas will still work; you will be prompted for establishing the link when you open your main sheet.

Dirty Data:


With numeric lookups, occasionally, the lookup key values may look like numbers, but are really textual. This can happen if the table is populated from a mainframe download or other ASCII import.

The symptoms are this: Both the lookup table and the lookup value might show '2356' -- but one is numeric and the other is character. When run through the VLookup, you will get an unexpected "Not Found" or NA.

To test the textual-data, make a dummy formula in another section of the lookup-sheet. Add +1 to your suspected numeric value. If it is text, the answer will be "1"; if numeric it will be '2357'. Do the same for the test value in the vlookup sheet.

If the 'numeric' values in the lookup sheet are really character, correct the issue by converting the lookup column to numeric data. Do this with these steps in the lookup columns:

a. Insert a new dummy column.
b. Use this formula: "=Value()"
c. Fill the formula down the column.
d. Copy the formulas; use Paste-Special, Values-only, over the top of the original "numbers".
e. Delete the dummy column.

You may also find the original data is polluted with non-printable characters -- usually a tab. Consider using similar steps with a =Clean() formula to spiff the data.


Non-Exact Searches


The last parameter in the VLookup (,"false"), tells Excel that an exact match must be found. This is the normal setting for the formula. However, you can specify a non-exact match. For example, if the dollar figures were between $1,000 and $2,000 dollars, use such-and-such General-Ledger number. But if the number were between $2,000 and $10,000, use a different number, etc.

Consider this table, which shows purchase-order approval ledger information:

Within your own sheet, a lookup of various items purchased, might look like this, where different ledger-numbers and approving people are displayed, depending on the dollar-amount spent:


The formula in cell D4 ($33.56 purchase) would look like this:
=VLOOKUP(B4,Accounts.xlsx!LedgerAccounts,2,TRUE)

where:
  • "LedgerAccounts" is a new RangeName in the lookup sheet.
  • "2" returns the second column (Ledger-account number)
  • "true" says allow inexact matches

With this type of lookup, you do not need the IfError logic used in previous examples -- there is no need unless you expect negative numbers to arrive.

In the lookups, Bob (Ledger account ABC) gets to approve all dollar purchases less than $1,000. If the purchase were $1,000.01, Mary gets the right to approve (not Bodine).

All purchases $30,000 or larger belong to Margret. The rule is this: If no exact match is found, find the next larger value that is less-than the looked-up value.

This concludes the VLookup tutorial. Your comments are welcome.

Related Keyliner Articles:
Excel UDF (User Defined Functions)
Using Excel for Raffle-Ticket Drawing: Prizeorama
Excel VLookup - a complete tutorial
Excel Coloring Alternate Rows
Excel Parsing City-State-Zip
Excel Importing Text with Leading Zeroes
VB - Return First Word, Last Word, Supertrim
Using VBA to Send Email
Using Excel to select Raffle Tickets - Prize-orama

Wednesday, February 3, 2010

Dell Inspiron 1545 Review

Review: First-look at the Dell Inspiron 1545 Laptop.

My daughter needed a laptop for school and it was time to retire her old 512mb machine. With an eye towards an inexpensive computer, we bought a Dell Inspiron 15 (Inspiron 1545). This is article is a cursory review of the computer.


Synopsis:
A capable, low-end machine, with a low-end video card, suitable for a student. I have no serious complaints about the machine itself, but hate the shiny-plastic cover.

I justified spending about $100 more than originally intended (total $520). But with this, I got an upgraded Intel processor, larger cache and 3G of RAM. Cheaper computers will come with Celeron or low-end AMD chips and 2G Ram.

If this were my personal machine, I would have upgraded the Video and I would have bought the Intel-branded Wireless Network card, but because my daughter would never know the difference, we kept the cost down. But in the same breath, many features on this computer are better than my high-end 2-year old XPS laptop and this computer is more capable than my then-expensive desktop.

The Good:
  • Dual Core Intel T4300 2.1ghz, 800mhz chip (upgraded)
  • 1M L2 Cache
  • 15" Glossy Screen 1366x768 (but narrow viewing angles)
  • 3G DDR2, 800MHz; 2 Dimms
  • 7-in-one Media Card; Express Card Slot
  • 3 USB ports
  • WebCam 1.3mpx
  • External VGA port
  • Small power supply (physical size)
  • Windows 7 Home Premium x64 (nice) with physical media
The Unremarkable:
  • Intel Graphics Media Accelerator X4500HD (onboard Video)
  • 250GB 5400RPM HD;
  • Standard Dell-branded Wireless and Wired NIC
  • Standard Laptop Keyboard, black
The Bad:
  • High-glossy cheapo-plastic palm rest; always looks bad; greasy
  • Default lid-color is black; other colors cost an amazing $40.
  • No HDD light
  • Moderate amount of "crapware"; easily removed
  • Unable to build Recovery Disks
  • No separate FKeys; you must press an option-number
  • Viewing angles on the LCD screen are narrow


In the Box

The machine ships in a box that is slightly bigger than the laptop and surprisingly survived shipment. It was delivered ground and arrived 6 days after placing the order. The computer comes with itself, a power-brick, and the following external DVD media, which was a pleasant surprise:
  • Windows 7 Home Premium 64-bit Re-installation DVD
  • Device Driver and Diagnostic DVD
  • Application DVD: Cyberlink, PowerDVD
  • Microsoft Works 9.0
  • (Other software, downloadable from Dell)

Glaring Problems


The most glaring problem with the computer is the cheap-plastic surrounding the keyboard and the display. This is a high-gloss, shiny-black plastic that looks horrible after touching it. There is no way on God's green Earth to keep fingerprints off this and it perpetually looks dirty. I am not a clean-freak, but this will keep me from buying this machine again. It is unbelievably annoying.

el'Cheap'o Issues:

It is hard to complain when you purposely bought a low-end machine, but 5400RPM hard drives? That is so 2007. And yet, this is what it shipped with. I suppose this will help with the battery life.

The onboard Intel Video card is ho-hum. Which is again, okay for a student computer. With another $50, I could have upgraded to a better video. Why care? The Video brought down the 'Windows Experience Index' (speed test) to a fairly low "3.8". Almost all other indexes were in the upper 4.8's and 5.5 ranges -- meaning this machine isn't half-bad, except for one component. Non-game-players would be hard-pressed to tell the difference.

At the risk of griping about the trivial: The computer comes in Model-T black. For an amazing $40, I could have upgraded to Blue or Red -- percentage-wise, this makes for an expensive premium that is unaffordable. Imagine if Dell offered the same color choices for $10. I'm sure people would be happier with their new computer and it wouldn't be such a thorn in the purchasing decision.

Software Crapware

As usual, there are things to un-install on almost every new computer. Here is a list of the software that was immediately removed:
  • McAfee 30-day trial
  • Microsoft Office trial
  • WildTangent Games
  • Windows Live (along with a half-dozen related programs)
  • Cozi Family Calendar
  • Microsoft SQL Server Express
  • Tablet PC Components

Dell's DataSafe Backup: You can do better

I did have problems with Dell's DataSafe backup. It claimed to make "Rescue Media," but after several failed attempts, I gave up; it refused to write to the DVD. I suspect the Roxio CD Burning software was running interference. The other features (full-disk data-backup, emergency backup, etc), required a paid upgrade. Because of this, I de-installed the software and decided to rely on an Acronis backup (not included).

McAfee Virus Scanning: Yikes
When I saw a 30-day McAfee virus scanner was installed, I immediately thought of all my clients in the past few years who have had either McAfee, Symantec, or AVG. In each case, I found this class of software to cause more problems than the viruses they were supposed to prevent. In particular, Mcafee is downright abusive when it comes to renewing their software and many of my clients have gone so far as to cancel their credit-cards to avoid charges.

As much as I would like a full suite of virus protection for my college-bound student, the overhead and hassles are not worth it. Instead, I opted to install Microsoft's free MSE virus scanner and will rely on backups. Yes, I know this is not ideal, but I want the machine to run.

Microsoft Office 30-day trial: Yea, right
A 30-day trial version of Microsoft Office is also installed. Because we had no intention on buying it, it was immediately un-installed. If you kept the software, can you imagine what it would be like if you needed to re-install without the installation media? This is simply too risky for such expensive software. (Here is a secret: Our family uses WordPerfect for word processing and we love it. Admittedly, Excel is a glorious program.)

The computer comes with a copy of Microsoft Works, which is okay for light-weight work and as much as people laugh about it, it is adequate for grade-school and high school use. You can do better with WordPerfect.

Windows Live: Designed by a committee
The computer also came with Windows-Live. I'm not exactly sure what this software does, but I know that neither myself nor my daughter use it. It was an adventure to un-install. Take a look at this list -- each had to be individually un-installed and each seemed to require a reboot: Windows Live Essential, Windows Live Mail, Windows Live Toolbar, Windows Live Signon Assistant, Windows Live Sync, and Windows Live Upload tool. This software must have been written by a committee. What a pain.

SQL Server? No fear
Remarkably, I found Microsoft SQL Server Express installed. I believe this was part of the Windows Live software (and the video-editing software that also came on the machine may use the same database). This was de-installed; I'm sure nobody will notice and the machine will be a lot faster without it.

WildTangentGames: A chance to shine, muffed
A free copy of WildTangentGames was installed and I was actually interested in keeping it. But when I launched the first game, the main menu was essentially a permanent nag, suggesting I upgrade to their premium content. I so wished I could start playing a game -- but there it was, right in my face, "click here to upgrade." Can't this be simple and unobtrusive? I didn't need the hassle and it was un-installed.

Too Busy System Tray
Finally, with steps too numerous to document here, the System Tray had a half-dozen unneeded processes. Things like the Intel Graphics HotKey program, Touchpad icons, Datasafe and RecoveryCD's -- all are not needed. Everything is visible in the Start Menu or the Control Panel. It took almost an hour to clean them up and I am still struggling to remove the last of them.

WebCam Software: Fun
On the plus-side, the computer comes with webcam software that has been fun to use. We are looking forward to playing with this.

Final Conclusions:

The machine is decent and I'm confident it will do what it was designed to do. It is hard to fault Dell for some of the pre-installed software, but it took a long evening of work to clean the computer. Sadly, you still have to be a geek to do it right. But the end result is a smooth-running, happy computer.




You may be interested in these geeky, yet wonderful Windows 7 cleanup steps:

Streamlining the Start Menu
Recommended Windows Explorer Changes
Optimizing the Windows Swap File
Cleaning Startup Programs
Exposing the Start Run command
Acronis 2010 Step-by-Step

Of course, as soon as I had the computer spiffed, I made an image-backup (the "Golden backup"). This will become the emergency recovery disk.

Some of my friends will be curious. Recent laptop names in the Wolf's household: "Electra", "Fortran", "Gerbil", "Hamster". This new computer is named "Ishmel". Electra was re-formatted and donated to a needy family that I know.

Comments welcome; no registration required.