Forum

Notifications
Clear all

Vlookup + Left Problem

8 Posts
3 Users
0 Reactions
139 Views
(@usb)
Posts: 244
Honorable Member
Topic starter
 

In the attachment I have 2 codes that I can't cross with Vlookup
Attached to the formula I have combined with LEFT
I would love to get help why it doesn't work.
Thank you!! Leah

 
Posted : 02/12/2019 3:27 am
Anders Sehlstedt
(@sehlsan)
Posts: 977
Prominent Member
 

Hello,

For reference.

The LEFT function returns its value in a text string, so you need to change it to be a numeric value. Use below formula and it will work.

=VLOOKUP(LEFT(A2,5)+0,D:E,2)

 
Posted : 02/12/2019 2:22 pm
(@usb)
Posts: 244
Honorable Member
Topic starter
 

Hi
As a follow up to a previous post, I made the change and it worked
The function I wrote is attached here in the file.
But, my problem now is that the Source sheet has 5-digit or 4-digit codes - and I only set the function to 5-digits, and as soon as it encounters a 4-digit code, it answers that it has not found the code.

How can this be arranged ??
Thanks so much, Leah

 
Posted : 03/12/2019 5:28 am
Anders Sehlstedt
(@sehlsan)
Posts: 977
Prominent Member
 

Hello,

Instead of setting a fixed parameter of 5 characters in the LEFT function, use LENGTH to check how many characters the lookup value has. Using previous formula as an example.

=VLOOKUP(LEFT(A2,LENGTH(D2))+0,D:E,2)

 
Posted : 03/12/2019 4:13 pm
(@usb)
Posts: 244
Honorable Member
Topic starter
 

Hi,
I wrote the formula but got the result NAME #
Attached File,
Why doesn't it work for me?

Thanks so much for answering !!

 
Posted : 03/12/2019 10:59 pm
Philip Treacy
(@philipt)
Posts: 1633
Member Admin
 

The function to check for the length of a string is LEN, not LENGTH 🙂

regards

Phil

 
Posted : 04/12/2019 12:02 am
Anders Sehlstedt
(@sehlsan)
Posts: 977
Prominent Member
 

Thanks Phil,

This is one of the hazards using functions in a different language and then translating when posting.

 
Posted : 04/12/2019 2:25 am
Philip Treacy
(@philipt)
Posts: 1633
Member Admin
 

LOL Anders.  I have the same issues when switching between VBA, PHP and JavaScript.  

 
Posted : 04/12/2019 3:46 am
Share: