Lookup Text Values

PARans

Board Regular
Joined
May 24, 2007
Messages
181
I am using a lookup on part numbers that can begin with a zero. In order for this to work the numbers have to be formatted as text. For some reason though I can not get my macro to work correctly. The following lookup returns "#N/A" although I have formatted the numbers to text in both sheets where the numbers appear. I find that if I stop the macro, go into the number in the cell and reenter it, the formula works.

Range(Cells(2, 1), Cells(lastrow, 2)).NumberFormat = "@" 'for text formating

With Range("R2").Resize(lastrow - 1)
.Offset.Formula = "=VLOOKUP(B2,'MIX PREVIOUS'!B:R,17,FALSE)"
.Offset.Copy
.Offset.Select
.Offset.PasteSpecial Paste:=xlPasteValues
.Offset.Application.CutCopyMode = False
End With

Help please!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Thank you for your response and the useful resource.

With further examination last night, I saw that the numbers had some trailing blanks spaces, so I converted the cells to text and removed any trailing spaces with the following code. Working great now.

'Format part numbers to text
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Range(Cells(2, 1), Cells(lastrow, 2)).NumberFormat = "@" 'for text formating

'Trim the part number for trailing spaces on the right
For i = 2 To lastrow
Cells(i, 2).Value = RTrim(Cells(i, 2))
Next i
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top