Change cell colour based on increase/decrease in previous value (same cell)

jayden13

New Member
Joined
Jul 27, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am looking for support to change a cell color based on whether or not it is an increase or decrease from the previous value.

For example if A1 is "1" and I manually changed it to "2", A1 fill color would change to green (increase) and if A1 was manually changed to 0, the color would change to red (decrease).

Thank you!
 
greetings
This function well, Copy and paste onto worksheet Module, please feed back

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim OldValue As String, NewValue As String
    Application.ScreenUpdating = False
        Application.EnableEvents = False
    On Error Resume Next
            Application.Undo
            OldValue = Target.Value
            Application.Undo
            NewValue = Target.Value
            
            If NewValue > OldValue And OldValue <> "" Then
                With Target
                    With .Interior
                        .Pattern = xlSolid
                        .Color = RGB(170, 207, 140)
                    End With
                    With .Font
                        .Color = RGB(55, 85, 35)
                    End With
                End With
            ElseIf NewValue < OldValue And OldValue <> "" Then
                With Target
                    With .Interior
                        .Pattern = xlSolid
                        .Color = RGB(255, 140, 140)
                    End With
                    With .Font
                        .Color = RGB(155, 0, 0)
                    End With
                End With
            End If
         On Error GoTo 0
        Application.EnableEvents = True
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
greetings
This function well, Copy and paste onto worksheet Module, please feed back

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim OldValue As String, NewValue As String
    Application.ScreenUpdating = False
        Application.EnableEvents = False
    On Error Resume Next
            Application.Undo
            OldValue = Target.Value
            Application.Undo
            NewValue = Target.Value
           
            If NewValue > OldValue And OldValue <> "" Then
                With Target
                    With .Interior
                        .Pattern = xlSolid
                        .Color = RGB(170, 207, 140)
                    End With
                    With .Font
                        .Color = RGB(55, 85, 35)
                    End With
                End With
            ElseIf NewValue < OldValue And OldValue <> "" Then
                With Target
                    With .Interior
                        .Pattern = xlSolid
                        .Color = RGB(255, 140, 140)
                    End With
                    With .Font
                        .Color = RGB(155, 0, 0)
                    End With
                End With
            End If
         On Error GoTo 0
        Application.EnableEvents = True
    Application.ScreenUpdating = True
   
End Sub
I like what you did there, but just thinking by reading what's here. Should the second undo be a redo instead?
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top