![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 12:08 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com