vlookup to pull info into a text box based on a combo box value in userform

ollieb34

New Member
Joined
Jan 27, 2021
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
Afternoon all,

I'm trying to pull a value from an adjacent cell within a table/range into a text box in a userform when the user selects an item from the combo box. See below code which I'm using that is returning a runtime error

1612628384867.png



Private Sub cmbProd_Change()

txtProd.Value = Application.VLookup(Me.cmbProd.Value, Sheets("Lookups").Range("C2:H17"), 2, 0)


End Sub

Any ideas as to what I could be doing wrong?

Thanks in advance
 
Try:
VBA Code:
    Private Sub cmbProd_Change()
    Dim x As Variant
    With Me.cmbProd
        If IsNumeric(.Value) And Not .Value = Empty Then
            x = Application.VLookup(CLng(.Value), Sheets("Lookups").Range("C2:H17"), 2, 0)
            If Not IsError(x) Then
                txtProd.Value = x
            Else
                MsgBox "NOT FOUND"
            End If
        End If
    End With

    End Sub
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try:
VBA Code:
    Private Sub cmbProd_Change()
    Dim x As Variant
    With Me.cmbProd
        If IsNumeric(.Value) And Not .Value = Empty Then
            x = Application.VLookup(CLng(.Value), Sheets("Lookups").Range("C2:H17"), 2, 0)
            If Not IsError(x) Then
                txtProd.Value = x
            Else
                MsgBox "NOT FOUND"
            End If
        End If
    End With

    End Sub
Akuini,
You have saved me... Spot on and working perfectly...

Well done and thanks again
 
Upvote 0
You're welcome, glad to help & thanks for the feedback. :)
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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