Error handling

  • Thread starter Thread starter Gareth
  • Start date Start date
G

Gareth

I am unable to handle a ceratin error that crops up when
the following code is run.

Sub compare()
Application.ScreenUpdating = False
Dim cell As Range
For Each cell in Sheets("Sheet2").Range("A2:A501")
Range("E6:E" & Range("E65536").End(xlUp).Row).Find
(cell.Value).Activate
'do stuff if cell.value found
Next cell
Application.ScreenUpdating = True
End Sub

My problem occurs when a value on sheet2 is not found in
column E on sheet1. I need an error handler to skip the
part that does stuff and starts again at Next cell.

Thanks in advance.

Gareth
 
Sub compare()
dim result as range
Application.ScreenUpdating = False
Dim cell As Range
For Each cell in Sheets("Sheet2").Range("A2:A501")
set result = Range("E6:E" & Range("E65536").End(xlUp).Row).Find(
(cell.Value))
IF not result is nothing then
'do stuff if cell.value found End If
Next cell
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top