vba – Loop through cell dependents – Education Career Blog

this expresses what I would like to do but obviously does not work. I think what I am trying to do is clear:

Get a cell, get its dependencies count, and output all of them.

Thanks in advance for any input

            Sub Extract()
            Dim i As Integer

                    For i = 1 To Workbooks("myBook.xls").Worksheets(1).Cells(14, 5).Dependents.Count
                        Debug.Print (Workbooks("myBook.xls").Worksheets(1).Cells(14, 5).Dependents(i))
                    Next i
            End Sub


You could do

Sub Extract()
Dim i As Range
    With Workbooks("Book1.xls").Worksheets(1).Cells(14, 5)
        For Each i In .Dependents
            Debug.Print i.Value i.Address
    Next i
    End With

End Sub



.Dependents is the transitive closure os .DirectDependents, and I’m not sure which of them you want … try both!

Leave a Comment