Displaying symbol on increase/decrease in cell value

dknowles2004

Board Regular
Joined
Nov 15, 2004
Messages
79
I'm not sure if this is do-able but I have a numeric value in cell D50. I'd like to make the background cell turn RED when the value decreases and GREEN when it increases.

Additionally, id like to display the word UP (for increase) and DOWN (for decrease) in cell D51.

Does anyone have any ideas on this?

Thanks.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Right click the sheet tab and choose View Code. Paste this into the window on the right.

Code:
Private Sub Worksheet_Calculate()
    Static OldValue As Double
    With Range("D50")
        If IsEmpty(OldValue) Then OldValue = .Value
        If .Value = OldValue Then
             Exit Sub
        ElseIf .Value < OldValue Then
            .Interior.ColorIndex = 3
            .Offset(1, 0).Value = "DOWN"
        Else
            .Interior.ColorIndex = 10
            .Offset(1, 0).Value = "UP"
        End If
        OldValue = .Value
    End With
End Sub

Press Alt+F11 to return to your worksheet.
 
Upvote 0
Thanks for you help. If I wanted to do this for multiple columns (eg. D50, F50, H50 etc) can I incorporate this into the code and how?

Thanks.
 
Upvote 0
Try this:

Code:
Private Sub Worksheet_Calculate()
    Static OldValues(1 To 3) As Double
    Const ColStep As Integer = 2
    Dim c As Integer
    Dim i As Integer
    c = 1
    With Range("D50")
        For i = LBound(OldValues) To UBound(OldValues)
            If IsEmpty(OldValues(i)) Then OldValues(i) = .Cells(1, c).Value
            If .Cells(1, c).Value < OldValues(i) Then
                .Cells(1, c).Interior.ColorIndex = 3
                .Cells(1, c).Offset(1, 0).Value = "DOWN"
            ElseIf .Cells(1, c).Value > OldValues(i) Then
                .Cells(1, c).Interior.ColorIndex = 10
                .Cells(1, c).Offset(1, 0).Value = "UP"
            End If
            OldValues(i) = .Cells(1, c).Value
            c = c + ColStep
        Next i
    End With
End Sub

To add more columns increase the upper bound of OldValues.
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,210
Members
448,874
Latest member
b1step2far

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