#1   Report Post  
Posted to microsoft.public.excel.misc
Mike McLellan
 
Posts: n/a
Default VLOOKUP

I am trying to use VLOOKUP to use a lookup value B5 to access an array to
return the value in column 2 of an array in another workbook. The expression
is as follows:

=VLOOKUP(B5,Temp!B5:D643,2,FALSE)

My problem is that, although looking at the values in B5 and Temp!B5 they
look identical, for some reason VLOOKUP is not recognising this. Also, if I
try =IF((B5=Temp!B7),"OK","Not OK") it comes up with 'Not OK'. Furthermore,
if I print out the ASCII character code for each character in each of the
strings, they are identical.

Can anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.misc
hans bal(nl)
 
Posts: n/a
Default VLOOKUP

The problem lies in the fact that somehow Excel does not recognize the data
as identical. Do you maybe have leading or trailing spaces in your data ? For
instance if the text in B5 = "John" and the text in B7 = "John ", you wil
get this problem.

Hans

"Mike McLellan" wrote:

I am trying to use VLOOKUP to use a lookup value B5 to access an array to
return the value in column 2 of an array in another workbook. The expression
is as follows:

=VLOOKUP(B5,Temp!B5:D643,2,FALSE)

My problem is that, although looking at the values in B5 and Temp!B5 they
look identical, for some reason VLOOKUP is not recognising this. Also, if I
try =IF((B5=Temp!B7),"OK","Not OK") it comes up with 'Not OK'. Furthermore,
if I print out the ASCII character code for each character in each of the
strings, they are identical.

Can anyone help?

  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default VLOOKUP

Most likely there is something different about the values in B5 and
Temp!B5 that is preventing an exact match. Is B5 formatted as a
number, and Temp!B5 is formatted as a string? It may be a leading or
trailing blank space, for instance, or one of the values may start with
an apostrophe(this usually happens when the value is imported from a
database or another application). You can test for this *using a
backed up copy of your data* copy copying the value in B5 to cell
Temp!B5. If the VLOOKUP returns the expected value then you'll need to
perform some secondary processing to remove the offending characters.

How did you print out the ascii code for each char in each string?
Just curious. Excel's CODE function, for instance, only returns the
ascii value for the first char in a cell.

  #4   Report Post  
Posted to microsoft.public.excel.misc
Mike McLellan
 
Posts: n/a
Default VLOOKUP

Nothing like that I'm afraid. I've printed out the ASCII code for each
character in both strings, from 1 to the last character +1, to prove this -
the results are identical

"hans bal(nl)" wrote:

The problem lies in the fact that somehow Excel does not recognize the data
as identical. Do you maybe have leading or trailing spaces in your data ? For
instance if the text in B5 = "John" and the text in B7 = "John ", you wil
get this problem.

Hans

"Mike McLellan" wrote:

I am trying to use VLOOKUP to use a lookup value B5 to access an array to
return the value in column 2 of an array in another workbook. The expression
is as follows:

=VLOOKUP(B5,Temp!B5:D643,2,FALSE)

My problem is that, although looking at the values in B5 and Temp!B5 they
look identical, for some reason VLOOKUP is not recognising this. Also, if I
try =IF((B5=Temp!B7),"OK","Not OK") it comes up with 'Not OK'. Furthermore,
if I print out the ASCII character code for each character in each of the
strings, they are identical.

Can anyone help?

  #5   Report Post  
Posted to microsoft.public.excel.misc
Mike McLellan
 
Posts: n/a
Default VLOOKUP

I did as you suggested and the VLOOKUP call is still returning an error

I used CODE(MID(x,y,1)) to print out all the ASCII codes

"Dave O" wrote:

Most likely there is something different about the values in B5 and
Temp!B5 that is preventing an exact match. Is B5 formatted as a
number, and Temp!B5 is formatted as a string? It may be a leading or
trailing blank space, for instance, or one of the values may start with
an apostrophe(this usually happens when the value is imported from a
database or another application). You can test for this *using a
backed up copy of your data* copy copying the value in B5 to cell
Temp!B5. If the VLOOKUP returns the expected value then you'll need to
perform some secondary processing to remove the offending characters.

How did you print out the ascii code for each char in each string?
Just curious. Excel's CODE function, for instance, only returns the
ascii value for the first char in a cell.




  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default VLOOKUP

Do you have the Analysis Toolpak installed?

  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default VLOOKUP

Your original post says
Also, if I try =IF((B5=Temp!B7),"OK","Not OK") it comes up with 'Not
OK'.

Assuming this is a typo and the IF should read B5=Temp!B5, this
suggests a formatting mismatch. If one is text and the other is
numeric, it will pass your ascii char code test and still fail the
VLOOKUP.

  #8   Report Post  
Posted to microsoft.public.excel.misc
Mike McLellan
 
Posts: n/a
Default VLOOKUP

Yes - it was a typo

I've tried reformatting both ranges as text but it doesn't appear to make
any difference

"Dave O" wrote:

Your original post says
Also, if I try =IF((B5=Temp!B7),"OK","Not OK") it comes up with 'Not
OK'.

Assuming this is a typo and the IF should read B5=Temp!B5, this
suggests a formatting mismatch. If one is text and the other is
numeric, it will pass your ascii char code test and still fail the
VLOOKUP.


  #9   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default VLOOKUP

Simply reformatting the range doesn't help unless you go into each
cell, edit, and press Enter. This is a macro that will do that for
you: please try this on a BACKUP copy of your file to avoid the
possibility of data loss. Suppose you want to verify / convert that
data in column D is text. At the bottom of column D, below the data in
question, enter the word "stop" (no quotes) in a cell. Set your cell
pointer at the top of column D and run this macro. It temporarily
stores the entry in memory, clears the cell, formats the cell as text,
and rewrites the entry into that cell with no leading or trailing
spaces.

Remember- run this on a BACKUP copy of your file! This little macro
has worked properly for me countless times- don't be the first to
figure out it creates problems on your setup.

Sub TrueVal()
With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

Dim TrueVal as String

Do Until ActiveCell.Value = "stop"
TrueVal = Trim(ActiveCell.Value)
ActiveCell.Value = ""
Selection.NumberFormat = "@" 'set format to Text
ActiveCell.Value = Trim(TrueVal)
ActiveCell.Offset(1, 0).Select
Loop

With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False

Calculate
End Sub

  #10   Report Post  
Posted to microsoft.public.excel.misc
JBS
 
Posts: n/a
Default VLOOKUP

Thank you so much for this macro. I have been struggling with this for days.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLOOKUP Problem Ian Excel Discussion (Misc queries) 3 April 6th 06 06:47 PM
VLOOKUP Limitations chris_manning Excel Worksheet Functions 2 August 9th 05 06:23 PM
Have Vlookup return a Value of 0 instead of #N/A Mr Mike Excel Worksheet Functions 4 May 25th 05 04:51 PM
vlookup data hidden within worksheet Excel Worksheet Functions 0 January 26th 05 12:09 PM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


All times are GMT +1. The time now is 12:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"