Rick Rothstein \(MVP - VB\)
3/24/2010 11:41:00 PM
As far as I know, that will only work for Precedent cells on the same
worksheet as the cell (Cel1 in this case)... Precedents will not work on
cells referencing other sheets. The only way I know to do that is how I
showed in my post... show the precedent arrows, then use NavigateArrow to
find the cell on the foreign sheet that you want and the turn the arrows
off. The code for this can get complicated if there are several cells on
other sheets, especially if there are multiple other sheets involved.
--
Rick (MVP - Excel)
"pbart" <pbart@discussions.microsoft.com> wrote in message
news:585812DF-6C7F-47D1-9343-777F2226D0AE@microsoft.com...
> Cel1.Precedents.Select
>
> will activate a range which is the union of cells appearing in the formula
> (Excel 2007).
>
> If you have trace arrows showing on your sheet then NavigateArrow will
> allow
> you to select a particular one to follow.
>
>
>
> "Ron Rosenfeld" wrote:
>
>> On Tue, 23 Mar 2010 22:10:08 -0700 (PDT), Jim Luedke <baobob@my-deja.com>
>> wrote:
>>
>> >This is a simple and possibly embarrassing question.
>> >
>> >In Excel 2002 SP3, cell 1 is on ProfitSheet and depends on cell 2, on
>> >a different sheet.
>> >
>> >Cell 1 has a UDF, so it looks like:
>> >
>> >"=MassageData(SalesSheet!$A$1)"
>> >
>> >Given that I know cell 1 at runtime, what VBA function returns cell 2?
>> >
>> >I have tried:
>> >
>> >Set Cel2 = Cel1.Precedents(1)
>> >Set Cel2 = Cel1.Precedents.Cells(1, 1)
>> >etc.
>> >
>> >but that only seems to return Cel1 itself (at least that's what the
>> >Debug Window shows).
>> >
>> >1) Is my syntax wrong?
>> >
>> >2) Is Excel's lack of external dependent/precedent functionality in my
>> >old version, the reason?
>> >
>> >3) If so, has that un-feature ever been fixed?
>> >
>> >I guess I could manually remove the UDF and do:
>> >
>> >Set Cel2 = Range(StripTheEqualSignAndUDFFrom(Cel1.Formula))
>> >
>> >or maybe this sickness (if I have the syntax right):
>> >
>> >Set Cel2 =
>> >Application.WorksheetFunction.INDIRECT(StripDitto(Cel1.Formula))
>> >
>> >But what's the simple way that's staring me in the face?
>> >
>> >Thanks much.
>> >
>> >***
>>
>> For the address, perhaps:
>>
>> rg.Precedents.Worksheet.Name & "!" & rg.Precedents.Address
>>
>> --ron
>> .
>>