![]() |
Loop through cells to find dependents
I having brain issues...
I've completely forgotten how to trap an error in a loop Here is what I have (watch out for lines wrapping): Sub MapDependencies() Dim cell As Range For Each cell In ThisWorkbook.Sheets("Summary").Range("A1:L64") ThisWorkbook.Sheets("Dependencies").Range("b65000" ).End(xlUp).Offset(1, 0).Value = cell.DirectDependents.Address ThisWorkbook.Sheets("Dependencies").Range("b65000" ).End(xlUp).Offset(0, -1).Value = cell.Address Next cell End Sub Cell A1 has no dependencies, so error 1004 'No cells were found' pops up. I can trap the first error in the loop, but if any other subsequent cell errs then it is no longer trapped. Any ideas? |
Loop through cells to find dependents
It turns out that I was trying to trap the phrase "No cells were found" and
it didn't recognize that. the code below works. Sub MapDependencies() Dim cell As Range For Each cell In ThisWorkbook.Sheets("Summary").Range("A1:L64") On Error GoTo errRoutine ThisWorkbook.Sheets("Dependencies").Range("a65000" ).End(xlUp).Offset(1, 0).Value = cell.Address ThisWorkbook.Sheets("Dependencies").Range("a65000" ).End(xlUp).Offset(0, 1).Value = cell.DirectDependents.Address Next cell errRoutine: If Err.Number = 1004 Then Resume Next End Sub "JNW" wrote: I having brain issues... I've completely forgotten how to trap an error in a loop Here is what I have (watch out for lines wrapping): Sub MapDependencies() Dim cell As Range For Each cell In ThisWorkbook.Sheets("Summary").Range("A1:L64") ThisWorkbook.Sheets("Dependencies").Range("b65000" ).End(xlUp).Offset(1, 0).Value = cell.DirectDependents.Address ThisWorkbook.Sheets("Dependencies").Range("b65000" ).End(xlUp).Offset(0, -1).Value = cell.Address Next cell End Sub Cell A1 has no dependencies, so error 1004 'No cells were found' pops up. I can trap the first error in the loop, but if any other subsequent cell errs then it is no longer trapped. Any ideas? |
All times are GMT +1. The time now is 06:11 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com