+ Reply to Thread
Results 1 to 6 of 6

VBA change font colour of cell if greater than/less than above cell

  1. #1
    Registered User
    Join Date
    03-11-2020
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    8

    VBA change font colour of cell if greater than/less than above cell

    Hello,

    I am new to VBA and I would like to know if there is a code to change the colour of the cells in this data set, depending on whether the cell is greater than or less than the cell above.

    Annotation 2020-03-12 105511.png

    For example, if A3 if greater than A2, then set font to green. If A3 is less than A2, then set font to red.

    I would like to repeat this pattern for the entire data set located in Set A. I would also like to apply this same code for the data in column B.

    However, for cell A2, I would like this to turn green if greater than B15, and red if less than B15. I would also like B2 to not be affected by any code. Basically B2 would be the starting point and A15 would be the end point.

    Is this possible?

    Thank you.

  2. #2
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,340

    Re: VBA change font colour of cell if greater than/less than above cell

    why not just conditional formatting?

    a green rule and a red rule like maybe

    Please Login or Register  to view this content.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  3. #3
    Registered User
    Join Date
    03-11-2020
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA change font colour of cell if greater than/less than above cell

    Thank you for the response and the suggestion.

    I was aiming to have this written in code just for a project and to try and build my skill without using formula.

    I was hoping there could be a way to write this into VBA.

    Thanks

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,498

    Re: VBA change font colour of cell if greater than/less than above cell

    Re: "However, for cell A2, I would like this to turn green if greater than B15, and red if less than B15"
    Is this always B15 or the last used cell in column B?
    What color if the values are identical?

    Please Login or Register  to view this content.
    Last edited by jolivanes; 03-12-2020 at 03:41 AM. Reason: Add suggestion

  5. #5
    Registered User
    Join Date
    03-11-2020
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA change font colour of cell if greater than/less than above cell

    Quote Originally Posted by jolivanes View Post
    Re: "However, for cell A2, I would like this to turn green if greater than B15, and red if less than B15"
    Is this always B15 or the last used cell in column B?
    What color if the values are identical?

    Please Login or Register  to view this content.
    Thank you!! This is great.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,498

    Re: VBA change font colour of cell if greater than/less than above cell

    Thanks for the feedback and good luck

+ 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. VBA : Change font colour within a cell up to nth character
    By mowens74 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2017, 04:35 PM
  2. If cell contains value greater than x then change font on another sheet
    By Lifeless in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-24-2014, 10:09 AM
  3. If cell contains value greater than x then change font on another sheet
    By Lifeless in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-24-2014, 09:55 AM
  4. Replies: 5
    Last Post: 07-25-2013, 08:24 AM
  5. Replies: 2
    Last Post: 10-08-2012, 08:10 AM
  6. Use VBA to change font colour of a cell based on its own value (date)
    By grahamc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2012, 03:57 PM
  7. [SOLVED] VBA. Change cell interior colour for greater visibility
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-17-2012, 03:36 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