VBA- runtime error 1004 - Vlookup

Raymondc190466

New Member
Joined
Aug 19, 2016
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi Everybody,

I have issues with the population of the textbox7, and get a runtime error once data is written to a specific worksheet.
Any ideas how to solve this?

VBA Code:
Private Sub UserForm_Initialize()
    
    With Worksheets("Supplier")
        ComboBox1.List = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
    With Worksheets("Combobox")
        ComboBox2.List = .Range("C1:C" & .Range("C" & .Rows.Count).End(xlUp).Row).Value
    With Worksheets("Combobox")
        ComboBox3.List = .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
    With Worksheets("Combobox")
        ComboBox4.List = .Range("E1:E" & .Range("E" & .Rows.Count).End(xlUp).Row).Value
    End With
    End With
    End With
    End With

Me.TextBox2.Value = "Benelux"
UserForm1.BackColor = RGB(0, 0, 255)
UserForm3.BackColor = RGB(0, 0, 255)
UserForm4.BackColor = RGB(0, 0, 255)
      
End Sub

Private Sub ComboBox1_Change()

Me.TextBox7.Text = Application.VLookup(ComboBox1.Value, Worksheets("Supplier").Range("A2:B69"), 2, False)
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I can't see how you would get a 1004 error on that line. A type mismatch, yes, but not a 1004.
 
Upvote 0
I can't see how you would get a 1004 error on that line. A type mismatch, yes, but not a 1004.
Hi Rory,

Updated the code, but still got an error:

1640597263845.png


VBA Code:
Private Sub UserForm_Initialize()
    Dim xRg As Range
    
    Set xRg = Worksheets("Supplier").Range("A2:B65")
    Me.ComboBox1.List = xRg.Columns(1).Value
    
    Private Sub ComboBox1_Change()

Me.TextBox7.Text = Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, xRg, 2, False)

End Sub

Example of data:

1640595671968.png
 
Upvote 0
That can’t be the actual code as it wouldn’t run at all.

The error if it did run would mean the lookup value isn’t being found. Is a value actually selected at the time?
 
Upvote 0
@Raymondc190466, You seem to have introduced more issues with you latest posting. Try this:

VBA Code:
Private Sub ComboBox1_Change()
    Dim xRg As Range
   
    With Worksheets("Supplier")
        Set xRg = .Range("A2:B" & .Range("A" & .Rows.Count).End(xlUp).Row)
    End With
   
    If IsError(Application.VLookup(Me.ComboBox1.Value, xRg, 2, False)) Then
        MsgBox "Unable to find " & Me.ComboBox1.Value
    Else
        Me.TextBox7.Text = Application.VLookup(Me.ComboBox1.Value, xRg, 2, False)
    End If
   
End Sub
 
Upvote 0
Solution
@Raymondc190466, You seem to have introduced more issues with you latest posting. Try this:

VBA Code:
Private Sub ComboBox1_Change()
    Dim xRg As Range
  
    With Worksheets("Supplier")
        Set xRg = .Range("A2:B" & .Range("A" & .Rows.Count).End(xlUp).Row)
    End With
  
    If IsError(Application.VLookup(Me.ComboBox1.Value, xRg, 2, False)) Then
        MsgBox "Unable to find " & Me.ComboBox1.Value
    Else
        Me.TextBox7.Text = Application.VLookup(Me.ComboBox1.Value, xRg, 2, False)
    End If
  
End Sub

Hi Alex,

Code is working, thank you very much!

To all other helpers ,Sorry if I caused any uncertainties.
Everybody thanks for the help and input!
 
Upvote 0

Forum statistics

Threads
1,224,802
Messages
6,181,054
Members
453,014
Latest member
Chris258

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