For this to work, the badge numbers on the second sheet have to be formatted
as text. Either format the entire column as TEXT or precede the badge
numbers there with a single apostrophe. This actually may be to your
advantage anyway, since this would preserve leading zeros in badge numbers
with them - and I'm betting the scanner will display a badge numbered
00040421A as 00040421A instead of 40421A.
You should also format column A on the first sheet, column where your bar
code reader places its entries, as TEXT also. Just click on the A column
identifier, then Format | Cells and choose Text from the list.
Since that last character is a 'wildcard' we only want '00040421 in our
lookup table.
Using my previous example, change the formulas to read like this:
in B2
=IF(LEN(A2)>0,VLOOKUP(LEFT(A2,LEN(A2)-1),'Sheet2'!$A:$C,2,FALSE),"")
and in C2
=IF(LEN(A2)>0,VLOOKUP(LEFT(A2,LEN(A2)-1),'Sheet2'!$A:$C,3,FALSE),"")
Since we're working with Text, it is more appropriate to use the LEN(A2)>0
test instead of just A2>0.
You should be able to get rid of your error handling with that in place also.
If there is nothing in column A it will display nothing (empty string: "")
If there is something in column A, it will take the all of the characters in
it except for the far right 1 character and compare that to entries in column
A on the second sheet and when it finds a match, returns name and employee ID.
Now, if there's an entry in A, but it can't be found in the table on Sheet2,
THEN you will see #N/A - but as I said before, I think that's a good thing
because it tells you that the scanned number does not match any
valid/authorized number in your lookup table.
If you wanted something 'really neat' and perhaps more ijit-proof, you could
go with this formula:
=IF(LEN(A2)>0,IF(ISNA(VLOOKUP(LEFT(A2,LEN(A2)-1),Sheet2!$A:$C,2,FALSE)),"No
Match",VLOOKUP(LEFT(A2,LEN(A2)-1),Sheet2!$A:$C,2,FALSE)),"")
=IF(LEN(A2)>0,IF(ISNA(VLOOKUP(LEFT(A2,LEN(A2)-1),Sheet2!$A:$C,3,FALSE)),"No
Match",VLOOKUP(LEFT(A2,LEN(A2)-1),Sheet2!$A:$C,3,FALSE)),"")
This will show the words "No Match" when an #N/A was about to come up. A
little prettier, and less confusing than just the error code.
Also, you may notice that I dropped the numbers from the range on Sheet2 -
using just the column letters. This works better for you also, probably.
You can keep adding new entries to Sheet2 without having to go back and
adjust your formulas on the first sheet.