Run-time error ' 1004': Application-defined or object defined error

dversloot1

Board Regular
Joined
Apr 3, 2013
Messages
113
I'm trying to get the ROW number from a specific sheet where a cell value has been found.
Cnt = 5
ID = 479
Row = 0 --> This should return 19 but for some reason it is returning a 0.

My code is:

Private Sub CommandButton1_Click()
Dim ID As Variant
Dim Row As Long
Dim Cnt As Long
Dim Analyst As String

Cnt = InStr(1, ListBox2.Value, "-")
ID = Trim(Left(ListBox2.Value, Cnt - 1))
On Error Resume Next
Row = Application.WorksheetFunction.Match(ID, Sheets("Data").Range("B1:B2000"), 0)
On Error GoTo 0

Analyst = "A" & Row

Sheets("Sheet1").Range("B4").Value = Sheets("Data").Range(Analyst).Value


End Sub

Anyone know why this is the case?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Trim and Left functions return TEXT strings, even if they are numeric characters.

Try changing
ID = Trim(Left(ListBox2.Value, Cnt - 1))
to
ID = Val(Trim(Left(ListBox2.Value, Cnt - 1)))
 
Upvote 0
Inconsistent data is the root of all evil in Excel.

So sometimes the ID will be a number, and sometimes it will be a Text String ?

Try
ID = Trim(Left(ListBox2.Value, Cnt - 1))
If IsNumeric(ID) Then ID = Val(ID)
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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