ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find 'Product not found' (https://www.excelbanter.com/excel-programming/320665-find-product-not-found.html)

Pat

Find 'Product not found'
 
Is there a way to find a cell(s) that causes an error when code is run. The
following code returns 'Product not found: 0' error. I have looked up and
down but cannot find the offending 3 cells.


For Each Target In rng1
sProd = Target.Parent.Cells(Target.Row, 18)

res = Application.Match(sProd, _
Worksheets("ControlCentre").Range("C77:C1000"), 0)
If Not IsError(res) Then
With Worksheets("ControlCentre")
' Will return quantity 'Back into stock'
If IsNumeric(Target.Value) Then
Set rng2 = .Cells(res + 76, icol)
rng2.Value = rng2.Value + Target.Value
End If
End With
Else
MsgBox "Product Not found: " & sProd
End If
Next



Jim Thomlinson[_3_]

Find 'Product not found'
 
Try something like this

On Error Goto Tada

Your code Here...

end sub
Tada:
msgbox target.address & " Caused an Error"
resume next
end sub
Exit sub


HTH

"Pat" wrote:

Is there a way to find a cell(s) that causes an error when code is run. The
following code returns 'Product not found: 0' error. I have looked up and
down but cannot find the offending 3 cells.


For Each Target In rng1
sProd = Target.Parent.Cells(Target.Row, 18)

res = Application.Match(sProd, _
Worksheets("ControlCentre").Range("C77:C1000"), 0)
If Not IsError(res) Then
With Worksheets("ControlCentre")
' Will return quantity 'Back into stock'
If IsNumeric(Target.Value) Then
Set rng2 = .Cells(res + 76, icol)
rng2.Value = rng2.Value + Target.Value
End If
End With
Else
MsgBox "Product Not found: " & sProd
End If
Next




Jim Thomlinson[_3_]

Find 'Product not found'
 
Sorry I was not looking close enough at your code...
Just put my message box immediately after your "Product not Found" Message...

sorry... I thought your code was throwing a run time error not your error
message...

"Pat" wrote:

Is there a way to find a cell(s) that causes an error when code is run. The
following code returns 'Product not found: 0' error. I have looked up and
down but cannot find the offending 3 cells.


For Each Target In rng1
sProd = Target.Parent.Cells(Target.Row, 18)

res = Application.Match(sProd, _
Worksheets("ControlCentre").Range("C77:C1000"), 0)
If Not IsError(res) Then
With Worksheets("ControlCentre")
' Will return quantity 'Back into stock'
If IsNumeric(Target.Value) Then
Set rng2 = .Cells(res + 76, icol)
rng2.Value = rng2.Value + Target.Value
End If
End With
Else
MsgBox "Product Not found: " & sProd
End If
Next





All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com