Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Error Handling doesn't work!

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error Handling doesn't work!

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



HamishMcT wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Error Handling doesn't work!



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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error handling. Francis Brown Excel Programming 3 December 1st 05 12:47 AM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Error Handling AA2e72E[_2_] Excel Programming 0 April 27th 04 04:06 PM


All times are GMT +1. The time now is 09:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"