Error Handling with Nested Loops
Dim rng as Range
For Counter = 1 To intNumTreaty
Sheets("FY Prem").Select
Range("B3").Select
Range(Selection, Selection.End(xlToRight)).Select
intNoCols = Selection.Columns.Count
For Counts = 1 To intNoCols
Sheets("FY Prem").Select
Range("A3").Select
strCurDate = ActiveCell.Offset(0, Counts).Value
strCurTreaty = ActiveCell.Offset(Counter, 0).Value
strCurGroup = strCurDate & strCurTreaty
Sheets("Acct Summary Pull").Select
Columns("A:A").Select
set rng = Selection.Find(what:=strCurGroup)
if not rng is nothing then
rng.Select
curFYPrem = ActiveCell.Offset(0, 4).Value
curRnPrem = ActiveCell.Offset(0, 5).Value
curFYComm = ActiveCell.Offset(0, 6).Value
curRnComm = ActiveCell.Offset(0, 7).Value
End if ' if not rng is nothing
Next Counts
Next Counter
End Sub
--
Regards,
Tom Ogilvy
"Ctal" wrote in message
om...
I've got a couple of nested loops. The inner loop does a 'find' on one
sheet. Based on the found cell, it loads some values into variables that
are used on another page. The problem is with errors. The 'find' item
may
occasionally not exist. If this is the case, I need for the loop to
continue with the next iteration. I've tried several approaches to fix
this
and still come up short. Any ideas appreciated, code posted below:
(Some code to determine intNumTreaties)
For Counter = 1 To intNumTreaty
Sheets("FY Prem").Select
Range("B3").Select
Range(Selection, Selection.End(xlToRight)).Select
intNoCols = Selection.Columns.Count
For Counts = 1 To intNoCols
Sheets("FY Prem").Select
Range("A3").Select
strCurDate = ActiveCell.Offset(0, Counts).Value
strCurTreaty = ActiveCell.Offset(Counter, 0).Value
strCurGroup = strCurDate & strCurTreaty
Sheets("Acct Summary Pull").Select
Columns("A:A").Select
Selection.Find(what:=strCurGroup).Activate
(Error can happen here, if so need to move to next Counts
at
this point)
curFYPrem = ActiveCell.Offset(0, 4).Value
curRnPrem = ActiveCell.Offset(0, 5).Value
curFYComm = ActiveCell.Offset(0, 6).Value
curRnComm = ActiveCell.Offset(0, 7).Value
(Some code here to work with the variables on other sheets)
Next Counts
Next Counter
End Sub
|