Run-time error 1004

gleamng

Board Regular
Joined
Oct 8, 2016
Messages
98
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Good morning everyone
i have been having a running battle with Run-time error 1004 on this code, while i had tried many online solutions, yet i am stuck with this error.
Summarily, after trying the vlookup function, i also tried index & match function and get the same error code, so i was thinking may worksheet function dont want to work for my pet project, please kindly help this novice out. below is my vba code and thank you for your support & help.

VBA Code:
Private Sub cmbItemID_Change()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("ProductMaster")

If Me.cmbItemID.Value = "" Then Me.txtRate.Value = ""

Else
    Me.txtRate.Value = Application.WorksheetFunction.VLookup(Me.cmbItemID.Value, sh.Range("B:F"), 5, False)
End If

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Tell us what is in cmbItemID. Ill guess a number. Make sure you are looking up the same thing. A textual numberfor example will not be found in a list of real numbers by vlookup.
 
Upvote 0
Tell us what is in cmbItemID. Ill guess a number. Make sure you are looking up the same thing. A textual numberfor example will not be found in a list of real numbers by vlookup.

Yes cmbItemID is a number.
Thanks
 
Upvote 0
How about
VBA Code:
Private Sub cmbItemID_Change()
Dim sh As Worksheet
Dim x As Variant
Set sh = ThisWorkbook.Sheets("ProductMaster")

If Me.cmbItemID.Value = "" Then Me.txtRate.Value = ""

Else
    x = Application.VLookup(Val(Me.cmbItemID.Value), sh.Range("B:F"), 5, False)
    If Not IsError(x) Then Me.txtRate.Value = x
End If

End Sub
 
Upvote 0
How about
VBA Code:
Private Sub cmbItemID_Change()
Dim sh As Worksheet
Dim x As Variant
Set sh = ThisWorkbook.Sheets("ProductMaster")

If Me.cmbItemID.Value = "" Then Me.txtRate.Value = ""

Else
    x = Application.VLookup(Val(Me.cmbItemID.Value), sh.Range("B:F"), 5, False)
    If Not IsError(x) Then Me.txtRate.Value = x
End If

End Sub

Thanks, it returned compile error: Else without If
 
Upvote 0
Try
VBA Code:
Private Sub cmbItemID_Change()
Dim sh As Worksheet
Dim x As Variant
Set sh = ThisWorkbook.Sheets("ProductMaster")

If Me.cmbItemID.Value = "" Then
   Me.txtRate.Value = ""
Else
    x = Application.VLookup(Val(Me.cmbItemID.Value), sh.Range("B:F"), 5, False)
    If Not IsError(x) Then Me.txtRate.Value = x
End If

End Sub
 
Upvote 0
Solution
Try
VBA Code:
Private Sub cmbItemID_Change()
Dim sh As Worksheet
Dim x As Variant
Set sh = ThisWorkbook.Sheets("ProductMaster")

If Me.cmbItemID.Value = "" Then
   Me.txtRate.Value = ""
Else
    x = Application.VLookup(Val(Me.cmbItemID.Value), sh.Range("B:F"), 5, False)
    If Not IsError(x) Then Me.txtRate.Value = x
End If

End Sub
Thanks a million, it worked ???
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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