Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default What is VBA equivalent to Tools/Auditing/Trace Dependents?

I just need to know whether a cell has dependents, yea or nay; I don't
need to identify them.

Thanks.

***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default What is VBA equivalent to Tools/Auditing/Trace Dependents?

Function CellHasPrecs(cell As Range) As Boolean
Dim rPrecs As Range

On Error Resume Next
Set rPrecs = Nothing
Set rPrecs = cell.Precedents

CellHasPrecs = Not rPrecs Is Nothing
End Function

Sub test()
Dim bHasPrecs As Boolean
Dim r As Range
Set r = Range("d5")

bHasPrecs = CellHasPrecs(r)

MsgBox bHasPrecs
End Sub

Regards,
Peter T
wrote in message
...
I just need to know whether a cell has dependents, yea or nay; I don't
need to identify them.

Thanks.

***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default What is VBA equivalent to Tools/Auditing/Trace Dependents?

I always forget both cell.Precedents and also cell.DirectPrecedents only
return precedents on the same sheet as 'cell'. This might be a bit better
but note the caveat in the comments, could further parse the formula to
decrease the possibility of returning a false positive.

Function CellHasPrecs(cell As Range) As Boolean
Dim rDirPrecs As Range

If cell.HasFormula Then

On Error Resume Next
Set rDirPrecs = cell.DirectPrecedents
On Error GoTo 0
If Not rDirPrecs Is Nothing Then
CellHasPrecs = True
ElseIf InStr(cell.Formula, "!") 0 Then
' formula contains an ! strongly indicates a ref to
' to another sheet but not 100% conclusive
CellHasPrecs = True
End If
End If

End Function

Regards,
Peter T


"Peter T" <peter_t@discussions wrote in message
...
Function CellHasPrecs(cell As Range) As Boolean
Dim rPrecs As Range

On Error Resume Next
Set rPrecs = Nothing
Set rPrecs = cell.Precedents

CellHasPrecs = Not rPrecs Is Nothing
End Function

Sub test()
Dim bHasPrecs As Boolean
Dim r As Range
Set r = Range("d5")

bHasPrecs = CellHasPrecs(r)

MsgBox bHasPrecs
End Sub

Regards,
Peter T
wrote in message
...
I just need to know whether a cell has dependents, yea or nay; I don't
need to identify them.

Thanks.

***





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default What is VBA equivalent to Tools/Auditing/Trace Dependents?

You can either use the .Dependents property, but as Peter said, this only
works with references within the sheet,
or you can use .ShowDependents followed by .NavigateArrow, which will
include off-sheet dependents.

warning: .showDependents and .NavigateArrow are a bit slow, if performance
is an issue look at only doing it once for similar blocks of formulae (use
R1C1 mode to find similar formulae).

regards
Charles
__________________________________________________
Outlines for my Sessions at the Australia Excel Users Group
http://www.decisionmodels.com/OZEUC.htm

wrote in message
...
I just need to know whether a cell has dependents, yea or nay; I don't
need to identify them.

Thanks.

***



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
trace all dependents Steve Excel Discussion (Misc queries) 1 February 11th 09 03:52 PM
trace dependents Susan B Excel Worksheet Functions 0 November 20th 06 10:28 PM
trace dependents JBoulton Excel Worksheet Functions 2 May 19th 05 09:04 PM
Trace Dependents Dean[_8_] Excel Programming 8 March 18th 05 07:55 AM
Trace dependents Dean[_8_] Excel Programming 10 March 5th 05 01:02 AM


All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"