VBA form will vlookup either text or numbers but not both

ScallN20

New Member
Joined
May 24, 2017
Messages
4
Hi All

I have another issue with the parts form I'm creating, I thought it was working but when building it originally I used only part numbers that were entirely numbers (Such as 439557) and in testing I have found that it wont work with part numbers that have a letter in them (Such as N01011).

I have found that if I add
Code:
"dim x as Double"
then the vlookup works for numbers but doesn't work for text same as
Code:
"x = val.parttxt"
works for numbers. and if I remove them entirely as is shown below it works for the part numbers with letters in... any ideas?
Code:
Private Sub PartTxt_AfterUpdate()


If WorksheetFunction.CountIf(Sheet1.Range("A:A"), Me.PartTxt.Value) = 0 Then
MsgBox "Part not found!"
Exit Sub
End If
With Me




x = PartTxt
    DesTxt.Value = Application.WorksheetFunction.VLookup(x, Worksheets("PartsData").Range("A:B"), 2, 0)
End With


End Sub

Thanks in advance
:)
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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