Error Handling doesn't work!

H

HamishMcT

Hi there,

If you can help me on what may seem like a trivial matter I would be
very much obliged - I am tearing my hair out!

I have a fairly simple formatting and sorting macro which handles a
specific error first time but the next time the same error appears in
the same module , it doesn't handle it at all!



On Error GoTo error1

Cells.Find(What:="1 total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate


is the first error handler (the label error1: is at the end of the
module after exit sub...). This works fine - the code jumps over this
bit as "1 total does not exist.

However, later on in the code, for example, I need to find the same
situation again so I have produced exactly the same code


On Error GoTo error1

Cells.Find(What:="1 total", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate


This time it throws a run time error! Aaaargh.

If anybody can advise why this might be the case I would be very
grateful.

Thanks and regards

Hamish
 
D

Dave Peterson

If you use a variable to represent that foundcell, you'll find that it makes
life easier.

Dim FoundCell as range

set foundcell = cells.find(....)
if foundcell is nothing then
'it wasn't found
else
foundcell.activate 'or whatever you want to do
end if
 
H

HamishMcT

Dave and Charles,

Thanks very much for your time - it's sorted now and you've been a
great help.

I'm still quite new to this game and find I'm picking up new stuff
every day...

Cheers
Hamish
 

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

Top