+ Reply to Thread
Results 1 to 11 of 11

VBA to analyze formula and highlight precedents on all sheets

  1. #1
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    VBA to analyze formula and highlight precedents on all sheets

    The built-in functionality allows you to double-click or click F2 and see all precedents highlighted, but only on the same sheet as the formula. This solution applies fill color to all immediate precedent cells on all sheets, and presents a UserForm to select which sheet to activate. Then closing the form restores the original formatting.

    See release notes for limitations. Also, it shows only immediate precedents, and not precedents of precedents.

    Consider this a beta test. I would be happy to entertain suggestions for corrections and enhancements.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA to analyze formula and highlight precedents on all sheets

    Update. Functionality is the same. Code has been updated to use a single regexp pattern that will cover both formats of sheet names. Also added a note that this will not parse 3D range references.

  3. #3
    Registered User
    Join Date
    03-13-2024
    Location
    Cambodia
    MS-Off Ver
    365
    Posts
    2

    Re: VBA to analyze formula and highlight precedents on all sheets

    nice VBA code. However, the code fails with just basic references. Eg., =+Sheet3!B7+Sheet2!B4
    How to fix this?
    Thank you

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA to analyze formula and highlight precedents on all sheets

    Why are you starting a formula with a "+" sign?

  5. #5
    Registered User
    Join Date
    03-13-2024
    Location
    Cambodia
    MS-Off Ver
    365
    Posts
    2

    Re: VBA to analyze formula and highlight precedents on all sheets

    even =Sheet3!B7+Sheet2!B4 still not work.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: VBA to analyze formula and highlight precedents on all sheets

    It says this in the opening line:

    The built-in functionality allows you to double-click or click F2 and see all precedents highlighted, but only on the same sheet as the formula.
    Your formula is referencing other sheets.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA to analyze formula and highlight precedents on all sheets

    Ali, that note refers to the built-in functionality. My version should work. I'll take a look at that example.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: VBA to analyze formula and highlight precedents on all sheets

    Oh, OK - my misunderstanding.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA to analyze formula and highlight precedents on all sheets

    Quote Originally Posted by leekosal View Post
    nice VBA code. However, the code fails with just basic references. Eg., =+Sheet3!B7+Sheet2!B4
    How to fix this?
    Thank you
    There seems to be an error in the regexp pattern for detecting references to external sheets if they are not enclosed in 'single quote' marks. I'll look into that.

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA to analyze formula and highlight precedents on all sheets

    Fixed bug in regex expression that now recognized sheet names if not enclosed in 'single quotes'. Note that this will not work for expressions that cannot occur in Excel formulas, like sheet names with special characters that are not in 'single quotes'.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA to analyze formula and highlight precedents on all sheets

    Here is what I think is a better solution. This gives you a list of all the range references and allows you to pick one to navigate to. This actually selects the ranges instead of highlighting them, which I think will be more useful in most cases.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Trace Multiple Precedents in a Formula
    By TLange in forum Excel General
    Replies: 4
    Last Post: 07-09-2022, 06:02 PM
  2. [SOLVED] How To Trace Precedents For The Cells On The Other Sheets?
    By zanshin777 in forum Excel General
    Replies: 6
    Last Post: 01-25-2022, 07:32 PM
  3. BUG in Excel re formula precedents
    By jasmith4 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-07-2016, 01:39 PM
  4. Highlight all cells in workbook having no precedents
    By gopal baheti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2014, 04:12 AM
  5. Macro to trace precedents across sheets
    By prod in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2007, 08:01 AM
  6. WHAT ARE REASONS THAT A FORMULA WILL NOT RESPOND TO PRECEDENTS?
    By Bizman in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-30-2006, 03:00 PM
  7. Replies: 3
    Last Post: 01-29-2005, 06:07 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1