
Tips.Net > ExcelTips Home > Tools > Auditing > Accessing Dependant and Precedent Information
Summary: The auditing tools in Excel allow you to easily see what cells are precedents to or dependent upon the current cell. In large, complex worksheets, you may find it helpful to extract this information and place it in a new worksheet where you can work with it more easily. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)
David rightly notes that Excel provides auditing tools (Trace Dependents and Trace Precedents) that are a very helpful way of keeping track of what is happening in large worksheets. However, the actual interface just lists out the cells in a small area, and David cannot easily copy out this list of cells to analyze and manipulate it. When he uses Trace Dependents on an important cell in a large worksheet, the small dialog box can contain several hundred references. David wonders if there is a relatively easy way of getting this information into a more usable format, like a blank worksheet or another workbook.
There is obviously no way to do this with native Excel commands, but you can create a macro that will extract the information you desire. The following macro will list the dependent cells for whatever cell is selected when you run the macro:
Sub ListDependents()
Dim rArea As Range
Dim rCell As Range
Dim rDep As Range
Dim lRow As Long
On Error Resume Next
Set rDep = ActiveCell.Dependents
If rDep Is Nothing Then
MsgBox ActiveCell.Address(False, False) & _
" has no dependents"
Exit Sub
End If
On Error GoTo 0
Worksheets.Add
lRow = 1
Cells(lRow, 1).Value = "Dependents for " _
& ActiveCell.Address(False, False)
For Each rArea In rDep
For Each rCell In rArea
lRow = lRow + 1
Cells(lRow, 1) = rCell.Address(False, False)
Next
Next
Set rArea = Nothing
Set rCell = Nothing
Set rDep = Nothing
End Sub
When the macro is first run, it checks to see if there are any dependents for the cell. If there aren't, then you are notified and the macro is exited. If there are dependents, then a new worksheet is added to the workbook and the dependents of the cell are added to the worksheet.
If you want the macro to instead list precedents, all you need to do is change the all instances of "Dependents" in the macro to "Precedents."
Tip #3121 applies to Microsoft Excel versions: 97 2000 2002 2003
Step Up and Take Control! Subscribers to ExcelTips know just how valuable a resource it is. ExcelTips Premium provides twice the number of exceptional, easy-to-understand tips every week in an ad-free newsletter, as well as substantial discounts on ExcelTips archives and e-books.
Check out ExcelTips Premium today!
It doesn't matter if you are a beginner or expert, the ExcelTips archives are the fastest way to improve your productivity. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Bugs and Pests Tips
ExcelTips
Family Tips
Health Tips
Home Tips
Organizing Tips
WordTips
Advertise on the
ExcelTips Site