Vlookup from Input Box VBA

Nase34

New Member
Joined
Apr 28, 2017
Messages
4
Hello and thank you in advance.

I am looking for a way to do a vlookup from an input box using VBA.

Basically I need to be able to enter a part number into the input box have it do a vlookup on my spreadsheet and select three cells from the row it finds the PN in to copy.

So for example in the attached spreadsheet I would want to be able to have a pop up box come up and say "Enter Part Number", I would then enter PN 12360 in this case it would vlookup this part in my spreadsheet and select and copy the PART NO (A17 in this case), the HERE DATE (K17 in this case), and the INTERNAL COMMENTS (L17 in this case)

I just need these to be copied to the clipboard for now. I inserted column letters and row numbers below for reference, in excel my A1 would be PART NO

[TABLE="width: 991"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[TD]E
[/TD]
[TD]F
[/TD]
[TD]G
[/TD]
[TD]H
[/TD]
[TD]I
[/TD]
[TD]J
[/TD]
[TD]K
[/TD]
[TD]L
[/TD]
[TD]M
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]PART NO
[/TD]
[TD]UNIT $
[/TD]
[TD]ST TY
[/TD]
[TD]DESCRIPTION
[/TD]
[TD]REQ QTY
[/TD]
[TD]REQ DATE
[/TD]
[TD]PO NO
[/TD]
[TD]PO QTY
[/TD]
[TD]DUE DATE
[/TD]
[TD]SHIP DATE
[/TD]
[TD]HERE DATE
[/TD]
[TD]INTERNAL COMMENTS
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]12345
[/TD]
[TD="align: right"]$0.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]06/01/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]12346
[/TD]
[TD="align: right"]$1.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]06/02/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]12347
[/TD]
[TD="align: right"]$2.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]4
[/TD]
[TD="align: right"]06/03/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]12348
[/TD]
[TD="align: right"]$3.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]5
[/TD]
[TD="align: right"]06/04/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]12349
[/TD]
[TD="align: right"]$4.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]6
[/TD]
[TD="align: right"]06/05/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]12350
[/TD]
[TD="align: right"]$5.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]7
[/TD]
[TD="align: right"]06/06/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]12351
[/TD]
[TD="align: right"]$6.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"]06/07/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]9
[/TD]
[TD]12352
[/TD]
[TD="align: right"]$7.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]9
[/TD]
[TD="align: right"]06/08/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD]12353
[/TD]
[TD="align: right"]$8.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]10
[/TD]
[TD="align: right"]06/09/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]11
[/TD]
[TD]12354
[/TD]
[TD="align: right"]$9.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]11
[/TD]
[TD="align: right"]06/10/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]12
[/TD]
[TD]12355
[/TD]
[TD="align: right"]$10.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]12
[/TD]
[TD="align: right"]06/11/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]13
[/TD]
[TD]12356
[/TD]
[TD="align: right"]$11.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]13
[/TD]
[TD="align: right"]06/12/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]14
[/TD]
[TD]12357
[/TD]
[TD="align: right"]$12.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]14
[/TD]
[TD="align: right"]06/13/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]15
[/TD]
[TD]12358
[/TD]
[TD="align: right"]$13.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]15
[/TD]
[TD="align: right"]06/14/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]16
[/TD]
[TD]12359
[/TD]
[TD="align: right"]$14.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]16
[/TD]
[TD="align: right"]06/15/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]17
[/TD]
[TD]12360
[/TD]
[TD="align: right"]$15.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]17
[/TD]
[TD="align: right"]06/16/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]18
[/TD]
[TD]12361
[/TD]
[TD="align: right"]$16.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]18
[/TD]
[TD="align: right"]06/17/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]19
[/TD]
[TD]12362
[/TD]
[TD="align: right"]$17.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]19
[/TD]
[TD="align: right"]06/18/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]20
[/TD]
[TD]12363
[/TD]
[TD="align: right"]$18.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]20
[/TD]
[TD="align: right"]06/19/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]21
[/TD]
[TD]12364
[/TD]
[TD="align: right"]$19.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]21
[/TD]
[TD="align: right"]06/20/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]22
[/TD]
[TD]12365
[/TD]
[TD="align: right"]$20.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]22
[/TD]
[TD="align: right"]06/21/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]23
[/TD]
[TD]12366
[/TD]
[TD="align: right"]$21.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]23
[/TD]
[TD="align: right"]06/22/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
[TR]
[TD]24
[/TD]
[TD]12367
[/TD]
[TD="align: right"]$22.0000
[/TD]
[TD]P
[/TD]
[TD]NUT,HEX #6-32 G8 ZN
[/TD]
[TD="align: right"]24
[/TD]
[TD="align: right"]06/23/17
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]12/31/30
[/TD]
[TD][/TD]
[TD="align: right"]04/30/17
[/TD]
[TD]Comment
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this...

Code:
Sub inputBox()


    Dim strPart As String
    Dim strDate As Date
    Dim strInternal As String
    Dim i As Integer
    Dim lngLastRow As Long
    
    lngLastRow = Range("A2").End(xlDown).Row
    
    strPart = Application.inputBox("Select a part")
    
    For i = 2 To lngLastRow
        If Cells(i, 1).Value = strPart Then
            strDate = Cells(i, 11).Value
            strInternal = Cells(i, 12).Value
        End If
    Next i


    MsgBox "Part Number: " & strPart & " Date: " & strDate & " Internal Comments: " & strInternal
    
End Sub
 
Upvote 0
Wow that was fast! Amazes me how quick some of you guys can knock this stuff out, thanks!!

This seems to work great! The only thing is, and I probably wasn't clear in my vague description, is instead of spitting out those 3 results in a message box I was looking to have them copied to the clip board. The goal would be to be able to paste them into a different program I use.

Thanks!
 
Upvote 0
Hello,

where do you want to copy to? Its not vlookup...the formula is following:

Code:
Sub test()
Dim thing As Variant

thing = InputBox("What are you looking for?", "Finding")

Cells.Find(thing).Select

Selection.Copy

End Sub
 
Upvote 0
Dphelps526 hit it pretty much on the head with his code, all I am saying is instead showing those values in a message box I would like the values of strPart, strDate, and strInternal copied to the clipboard so I could copy them to another program or even copy them into another spreadsheet
 
Upvote 0
While you're in the VBA editor:
Click Tools>References
Check the box next to "Microsoft Forms 2.0 Object Library."

Then:

Code:
Sub inputBox()


    Dim strPart As String
    Dim strDate As Date
    Dim strInternal As String
    Dim i As Integer
    Dim lngLastRow As Long
    
    Dim clipboard As MSForms.DataObject
    Dim myData As String
    
    Set clipboard = New MSForms.DataObject
    
    lngLastRow = Range("A2").End(xlDown).Row
    
    strPart = Application.inputBox("Select a part")
    
    For i = 2 To lngLastRow
        If Cells(i, 1).Value = strPart Then
            strDate = Cells(i, 11).Value
            strInternal = Cells(i, 12).Value
        End If
    Next i
    
    myData = strPart & " " & strDate & " " & strInternal
    clipboard.SetText myData
    clipboard.PutInClipboard
    
End Sub

Then try pasting in a word document or whatever to see if it worked
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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