Vlookup not importing values

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
I have a userform in which the listbox populates with part numbers.
When the user selects a part number this form then closes & another opens.
The listbox part number that was selected is now in the textbox called MyPartNumber.
All the other Textboxes now take notice of the value in MyPartNumber & populate there own Textbox.

This is where it fails.
When the value is placed in the textbox MypartNumber i see a message Method Range Of Object Failed RTE1004

I have a database on sheet INFO where at column Y is the value for MyPartNumber then to the right are the values that should be populating the other textboxes.

I dont see how the part numbers get into the form.

Code shown here & fails on first line

Rich (BB code):
Private Sub MyPartNumber_AfterUpdate()
'Set the background to grey (in case its currently red due to an incorrect length part number having been entered)
Me.MyPartNumber.BackColor = RGB(180, 180, 180)
If MyPartNumber.Text = "" Then Exit Sub

'Add - characters if 11 part number is 11 characters long
If Len(Me.MyPartNumber.Value) = 11 Then Me.MyPartNumber.Value = Left(Me.MyPartNumber.Value, 5) & "-" & Mid(Me.MyPartNumber.Value, 6, 3) & "-" & Right(Me.MyPartNumber.Value, 3)

'Turn background red if part number is wrong length
If Len(Me.MyPartNumber.Value) <> 13 Then
Me.MyPartNumber.BackColor = RGB(255, 0, 0)
Me.MyPartNumber.SetFocus
Exit Sub
End If

'Check to see if value exists
If WorksheetFunction.CountIf(Sheet8.Range("Y:Y"), Me.MyPartNumber.Value) = 0 Then
PartNumberMessage.Show
Me.MyPartNumber.Value = ""
Me.MyPartNumber.SetFocus
Exit Sub
End If

'Lookup values based on first control
With Me
.HondaPartNumber = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 2, 0)
.NumbersOnCase = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 3, 0)
.NumbersOnPcb = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 4, 0)
.Buttons = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 5, 0)
.GoldSwitchesOnPcb = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 6, 0)
.ItemType = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 7, 0)
.Notes = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 8, 0)
.Upgrade = Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 9, 0)
.MyPrice = Format(Application.WorksheetFunction.VLookup(Me.MyPartNumber, Sheet8.Range("HONDAORIGINALNUMBERS"), 10, 0), "£#,##0.00")
End With
End Su
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
In Sheet8.Range("HONDAORIGINALNUMBERS") are "partnumbers" stored as "Numbers" or "Text"? I.e., if you format that column as "number with 2 decimal" will they be shown (a) with 2 decimals or (b) will they still be displayed without decimals?
If "(b)" then we have to do some other investigations; if it is "(a)" then try modifying the vlookup as follows:
VBA Code:
.HondaPartNumber = Application.WorksheetFunction.VLookup(CLng(Me.MyPartNumber), Sheet8.Range("HONDAORIGINALNUMBERS"), 2, 0)

If that works, then be aware that my suggestion is that you forget abount the many Application.WorksheetFunction.VLookup and turn using one Application.Match, using the below approach:
VBA Code:
Dim pNum As Variant

'Lookup values based on first control
pNum = Application.Match(CLng(Me.MyPartNumber), Application.WorksheetFunction.Index(Sheet8.Range("HONDAORIGINALNUMBERS"), 0, 1), False)
If Not IsError(pNum) Then
    With Me
        .HondaPartNumber = Sheet8.Range("HONDAORIGINALNUMBERS").Cells(pNum, 2)
        .NumbersOnCase = Sheet8.Range("HONDAORIGINALNUMBERS").Cells(pNum, 3)
        'etc
        'etc
    End With
End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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