![]() |
Problem with Error handling in loop (with find)
I have created the following peace of code:
'Finds company within the peer group On Error Goto CompanyNotPartofPeerGroup Cells.Find(What:=ExcludedCompany, After:=Cells(1, 1), LookIn:=xlFormulas, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Activate 'Eliminates the analyzed company if it is truly part of the peer group ActiveCell.FormulaR1C1 = "=ROW()" temp = ActiveCell.Value Rows(temp).Delete shift:=xlUp CompanyNotPartofPeerGroup: On Error Goto 0 The problem is that this works the first time the code is run (so if the company is not part of the peer group a row is not deleted, but rather it goes to CompanyNotPartofPeerGroup). But the second time the code is run (part of the loop) and if the company analyzed is not part of the peer group, then the Error Handling breaks down and instead of going to CompanyNotPartofPeerGroup it handles the procedure as if I had written "On Error Resume Next"... Any ideas? |
Problem with Error handling in loop (with find)
See response in .excel group.
-- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Wesslan" wrote in message ... I have created the following peace of code: 'Finds company within the peer group On Error Goto CompanyNotPartofPeerGroup Cells.Find(What:=ExcludedCompany, After:=Cells(1, 1), LookIn:=xlFormulas, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Activate 'Eliminates the analyzed company if it is truly part of the peer group ActiveCell.FormulaR1C1 = "=ROW()" temp = ActiveCell.Value Rows(temp).Delete shift:=xlUp CompanyNotPartofPeerGroup: On Error Goto 0 The problem is that this works the first time the code is run (so if the company is not part of the peer group a row is not deleted, but rather it goes to CompanyNotPartofPeerGroup). But the second time the code is run (part of the loop) and if the company analyzed is not part of the peer group, then the Error Handling breaks down and instead of going to CompanyNotPartofPeerGroup it handles the procedure as if I had written "On Error Resume Next"... Any ideas? |
All times are GMT +1. The time now is 01:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com