Consulting

Results 1 to 3 of 3

Thread: Why so hard to get a cell's formula dependents/precedents

  1. #1

    Why so hard to get a cell's formula dependents/precedents

    I've been working on code which traverses a cell's formula dependents (precedents too -- please assume both throughout), and it seems Microsoft fights you all the way! If a cell's dependent is on a different tab, the cell's Dependents property yields an error! But you CAN use ShowDependents and then NavigateArrow -- but only if the tab that has the dependent is visible: what if it's hidden? And forget it if it's in a different file, and the file isn't open. Yet Excel's UI can put up a list of the dependents if you double-click the external-dependent arrow, so it must be possible to get a list of all dependents.

    The only way I've found to get a complete list is to set up a double-loop, one for arrow number, one for external-link index, and keep trying NavigateArrow until the selection doesn't move. But again, each dependent's tab has to be visible, and each relevant file has to be open.

    Is there REALLY no way of just getting a list or collection of dependents, which, if empty, would have a Count/CountLarge property equal to zero? Really, Microsoft??

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Yes, It isn't easy.
    I've written that double loop myself a few times. (And it misses any references to closed workbooks.)

    Why is (are) .DependentCells is only the cells on the same sheet as the precedent cell.

    It returns a Range object. The cells of a Range object have to all be on the same sheet. If .DependentCells returned all dependent cells, it would have to be a collection (to include dependents that were on different sheets). I don't know why Microsoft went the Range object choice, but that explains why DependentCells are all on the same sheet as the precedent cell.

    I don't know why you are working on this, but (FYI) if you Cut/Paste (rather than Copy/Paste) all dependent and precedent references will adjust automatically.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •