PC Review


Reply
Thread Tools Rate Thread

How Determine, cell has got reference.

 
 
=?Utf-8?B?a3Jpcw==?=
Guest
Posts: n/a
 
      29th Sep 2007
Hi, Kris here
I want to know how to determine wheather a cell in a worksheet has got
reference to other workshhet or reference in the same worksheet.

Thanks
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      29th Sep 2007
Hi Kris,

Sub Test()
Dim cel As Range, ar As Range
Dim rDeps As Range, rDirDeps As Range, rDirPrecs As Range

Set cel = Range("B2")

On Error Resume Next
Set rDeps = cel.Dependents
Set rDirDeps = cel.DirectDependents
Set rDirPrecs = cel.DirectPrecedents
On Error GoTo 0

If Not rDeps Is Nothing Then
For Each ar In rDeps.Areas
Debug.Print ar.Address
For Each c In ar.Cells
Debug.Print , c.Address
Next
Next
End If
If Not rDirDeps Is Nothing Then
For Each ar In rDirDeps.Areas
Debug.Print ar.Address
For Each c In ar.Cells
Debug.Print , c.Address
Next
Next
End If

If Not rDirPrecs Is Nothing Then
For Each ar In rDirPrecs.Areas
Debug.Print ar.Address
For Each c In ar.Cells
Debug.Print , c.Address
Next
Next
End If

End Sub

Regards,
Peter T


"kris" <(E-Mail Removed)> wrote in message
news:BD1CC184-4618-4046-9D47-(E-Mail Removed)...
> Hi, Kris here
> I want to know how to determine wheather a cell in a worksheet has got
> reference to other workshhet or reference in the same worksheet.
>
> Thanks



 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      29th Sep 2007
Sorry, that doesn't answer your question at all, will look later

Regards,
Peter T

"Peter T" <peter_t@discussions> wrote in message
news:%(E-Mail Removed)...
> Hi Kris,
>
> Sub Test()
> Dim cel As Range, ar As Range
> Dim rDeps As Range, rDirDeps As Range, rDirPrecs As Range
>
> Set cel = Range("B2")
>
> On Error Resume Next
> Set rDeps = cel.Dependents
> Set rDirDeps = cel.DirectDependents
> Set rDirPrecs = cel.DirectPrecedents
> On Error GoTo 0
>
> If Not rDeps Is Nothing Then
> For Each ar In rDeps.Areas
> Debug.Print ar.Address
> For Each c In ar.Cells
> Debug.Print , c.Address
> Next
> Next
> End If
> If Not rDirDeps Is Nothing Then
> For Each ar In rDirDeps.Areas
> Debug.Print ar.Address
> For Each c In ar.Cells
> Debug.Print , c.Address
> Next
> Next
> End If
>
> If Not rDirPrecs Is Nothing Then
> For Each ar In rDirPrecs.Areas
> Debug.Print ar.Address
> For Each c In ar.Cells
> Debug.Print , c.Address
> Next
> Next
> End If
>
> End Sub
>
> Regards,
> Peter T
>
>
> "kris" <(E-Mail Removed)> wrote in message
> news:BD1CC184-4618-4046-9D47-(E-Mail Removed)...
> > Hi, Kris here
> > I want to know how to determine wheather a cell in a worksheet has got
> > reference to other workshhet or reference in the same worksheet.
> >
> > Thanks

>
>



 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      29th Sep 2007
Cell have a "Precedents" collection, but this doesn't include references to
other sheets, only the sheet the cell is in.

It would be tricky to determine absolutely (using VBA) whether there are any
references to other sheets - you will have to take into account such things
as named ranges. And of course any use of INDIRECT() will also pose a
problem.

I'd be interested in seeing what others might suggest though.

Tim


"kris" <(E-Mail Removed)> wrote in message
news:BD1CC184-4618-4046-9D47-(E-Mail Removed)...
> Hi, Kris here
> I want to know how to determine wheather a cell in a worksheet has got
> reference to other workshhet or reference in the same worksheet.
>
> Thanks



 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      30th Sep 2007
Tricky! Tim has outlined the basic problem, namely the Dependents &
Precedents collections only include cells on same sheet. That implies a lot
of tedious parsing of cell formulas throughout the entire wb is required
looking for cell references, not to mention use of Indirect, Named formulas
and no doubt elsewhere such as CF's.

I had assumed, unfortunately wrongly it seems, that because Trace Dependents
& Precedents indicates references on other sheets there would be a simpler
way.

Regards,
Peter T

PS, I haven't checked the archives but this surely must have come up before.


"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> Sorry, that doesn't answer your question at all, will look later
>
> Regards,
> Peter T
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell reference to determine filename cangiff Microsoft Excel Programming 1 5th Jun 2009 03:32 PM
RE: Cell reference to determine filename Jacob Skaria Microsoft Excel Programming 0 5th Jun 2009 03:05 PM
problem with cell reference in =sum(offset(cell reference,x,y,z,a)). Want cell ref to be variable. twister212atop@yahoo.com Microsoft Excel Worksheet Functions 2 11th Dec 2004 12:05 AM
HOW-TO: Determine if a cell contains a number vs. formula vs. reference List Lurker Microsoft Excel Programming 4 11th Oct 2004 05:48 AM
HOW-TO: Determine if a cell contains a number vs. formula vs. reference List Lurker Microsoft Excel Worksheet Functions 2 10th Oct 2004 11:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:44 PM.