+ Reply to Thread
Results 1 to 6 of 6

Macro to highlight a cell if greater

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Ames, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    50

    Macro to highlight a cell if greater

    Can someone please help me with the code to do the following:
    If cell J31 is greater than cell y31, highlight cell B4 (yellow fill)
    If cell y31 is greater than cell j31, highlight cell B8 (yellow fill)
    If cell y31 and j31 are equal, don't highlight anything.
    Thanks!

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro to highlight a cell if greater

    How about using conditional formatting? Is this an option!
    HTH
    Regards, Jeff

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to highlight a cell if greater

    Hi,

    You don't need a macro. Use the Conditional formatting functionality.

    In the conditional format for B4 'Use a formula' option
    =IF(J31>Y31)
    and choose the yellow fill. Similarly in the cf for B8
    =IF(Y31>J31)

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro to highlight a cell if greater

    You can even drop the IF part

    B4 =J31>Y31
    B8 =Y31>J31

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to highlight a cell if greater

    Well spotted Jeff.

    Thanks...

  6. #6
    Registered User
    Join Date
    06-14-2012
    Location
    Ames, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Macro to highlight a cell if greater

    Guys, thanks for your help. You were right, the conditional formatting worked well for what I needed.
    Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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