Vlookup vba

kevin1970

New Member
Joined
Jun 2, 2011
Messages
11
Hi All
been a member for a while now, always been able to work problems out but cannot get this one to work. Please help.

I am setting up a check list for spares. From my form i have check the number is available button. on pressing the button it runs the code. i have a sheet called 'spares' and column 'A' is the part number i am trying to look up. When i run to code its asked me for the part number to check and the ends and give an error '1004' unable to get vlookup property of worksheet function class. can anyone help.

Private sub Check_click()
Dim part number as range
Dim number as variant
Dim partnumber as variant
Sheets("spares").activate
set part number = sheets("spares").Range("a1:a135")
partnum=inputbox("enter number to check ")
Number=worksheetfunction.vlookup(partnum,partnumber,1,false)
msgbox partnum & "is available " & number
end sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Maybe

Code:
Private Sub Check_click()
Dim partnumber As Range
Dim number As Variant
Dim partnumber As Variant
Sheets("spares").Activate
Set partnumber = Sheets("spares").Range("a1:a135")
partnum = Val(InputBox("enter number to check "))
number = Application.VLookup(partnum, partnumber, 1, False)
MsgBox partnum & "is available " & number
End Sub
 
Upvote 0
Code:
Private Sub Check_click()
    Dim partnumber As Range
    Dim number As Variant
    Dim partnum As Integer
    Sheets("spares").Activate
    Set partnumber = Sheets("spares").Range("a1:a135")
    partnum = InputBox("enter number to check ")
    number = WorksheetFunction.VLookup(partnum, partnumber, 1, False)
    MsgBox partnum & "is available " & number
End Sub

Although if a match is not found by vlookup, it throws up an error, so you might need an error handler
 
Last edited:
Upvote 0
Maybe

Code:
Private Sub Check_click()
Dim partnumber As Range
Dim number As Variant
Dim partnumber As Variant
Sheets("spares").Activate
Set partnumber = Sheets("spares").Range("a1:a135")
partnum = Val(InputBox("enter number to check "))
number = Application.VLookup(partnum, partnumber, 1, False)
MsgBox partnum & "is available " & number
End Sub


that work thanks.

Now what I don't know how to do is if the part number in not in the spares sheet I want to return 'part not available' do you know how I can do it?
thanks kev
 
Upvote 0
Try

Code:
Private Sub Check_click()
Dim partnumber As Range
Dim number As Variant
Dim partnumber As Variant
Sheets("spares").Activate
Set partnumber = Sheets("spares").Range("a1:a135")
partnum = Val(InputBox("enter number to check "))
number = Application.VLookup(partnum, partnumber, 1, False)
If IsError(number) Then
    MsgBox "Not found", vbExclamation
Else
    MsgBox partnum & "is available " & number, vbInformation
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,995
Members
448,539
Latest member
alex78

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