+ Reply to Thread
Results 1 to 3 of 3

Macro to highlight cells with differing formulas

  1. #1
    Registered User
    Join Date
    07-28-2008
    Location
    New York
    Posts
    12

    Macro to highlight cells with differing formulas

    I have a large and complex workbook. For the most part, every row contains the same formula with relative references copy and pasted to the right. I.e. A3 = A$1 * A2, A4 = A$1 * A3, A5 = A$1 * A4, etc.

    However, there are some cells where the formula will change. Sometimes intentionally, and sometimes in error.

    I want a way to highlight any cell where the formula changes so I can check the workbook for errors or correct a change I no longer need. I.e., highlight A5 in this example: A3 = A$1 * A2, A4 = A$1 * A3, A5 = A4 * B7.

    Short of writing my own routine to parse the starting formula (A3 = A$1 * A2) and computing the resulting formula (A4 = A$1 * A3) and comparing that to the actual formula in A4, is there a way to make Excel do this for me? I was thinking something along the lines of a VBA function that will take a cell reference and "copy/paste" the formula virtually into an adjacent cell without actually pasting it?

    Suggestions appreciated.

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Macro to highlight cells with differing formulas

    I came up with this algorithm: employ a helper range, to fill this range with autofill formula, then compare with formula range, then highlight cells those difference in formula.
    But, it depends on what kink of used formula, fill down or fill accross
    In your sample, it is filling down.
    Suppose formula range is A3:B10, in which
    A3 = $A$1*A2 and filled down
    B3=$A$1+A3 and filled down

    Now, make a test by manual changing formula in cells, i.e, A6 & B4

    they will be highlighted with red.

    PHP Code: 
    Option Explicit
    Sub checkformula
    ()
    Dim cell As RangecheckRng As Rangetmp As Range
    Set checkRng 
    Range("A3:B10"' change to actual range to check
    Set tmp = checkRng.Offset(, 1000) ' 
    employ a helper range (the 1000th column to the right of checked rangemake sure it is available)
    tmp.Rows(1).Formula Range("A3:B3").Formula 'copy formula of first row
    tmp.FillDown '
    fill formula to bottom
    For Each cell In checkRng
        
    If cell.Interior.Color vbRed Then cell.Interior.Color xlNone
        
    If cell.HasFormula Then
            
    ' compare manual formula in checked range with filled formula in tmp range
            If cell.Offset(, 10).Formula <> cell.Formula Then cell.Interior.Color = vbRed
        End If
    Next
    tmp.ClearContents
    End Sub 
    Attached Files Attached Files
    Last edited by bebo021999; 09-14-2022 at 01:09 AM.
    Quang PT

  3. #3
    Registered User
    Join Date
    07-28-2008
    Location
    New York
    Posts
    12

    Re: Macro to highlight cells with differing formulas

    Thank you.

    Attached is a macro workbook with my implementation of bebo's suggestion.

    Quercus
    Attached Files Attached Files

+ 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. Colour highlight differing cells between ranges
    By Hurley379 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2021, 08:42 AM
  2. Replies: 0
    Last Post: 04-26-2021, 07:46 AM
  3. Highlight cells with specific formula - VBA
    By andyzz in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 07-22-2017, 09:41 AM
  4. [SOLVED] How do i link formulas to total data from 2 colums with differing subjects.
    By meckenzie2012 in forum Excel General
    Replies: 4
    Last Post: 12-02-2012, 12:27 PM
  5. Ctrl+Shift+Enter (CSE) array formulas in VBA using differing formulas
    By officeguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2012, 04:31 PM
  6. How do I highlight cells on a worksheet that contain formulas
    By Rick S. in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-18-2006, 08:10 AM
  7. excel charting formulas - sum of 2 columns with differing data
    By John Watson @ barkoff container in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-19-2005, 10:05 AM

Tags for this Thread

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