Loop through cells to find dependents

J

JNW

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?
 
J

JNW

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top