Change font color if cell value changes

LabLady11

New Member
Joined
Oct 22, 2021
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
Hi All!

I'm looking for a VBA code to change the font color from black to red if the date in a cell changes from a previous value.

For example, I have a file where dates will be entered in columns D, H, K from row 3 onward. I will need to know when any date changes from its previous value (not including a change from blank to the initial date entered).

Any suggestions?

Thanks in advance!
LL
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Please try the following on a copy of your workbook. Put the code in the sheet code module of the sheet where it is to be applied - right-click the sheet tab name, select View Code and put the code in the blank window that appears on the right of the screen.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("D:D,H:H,K:K"), Target) Is Nothing Then
        Application.EnableEvents = False
        Dim OldVal As String, NewVal As String
        NewVal = Target.Value
        Application.Undo
        OldVal = Target.Value
        If OldVal <> "" And Target.Row > 2 Then
            Target.Value = NewVal
            Target.Font.Color = vbRed
        Else
            Target.Value = NewVal
        End If
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Solution
Please try the following on a copy of your workbook. Put the code in the sheet code module of the sheet where it is to be applied - right-click the sheet tab name, select View Code and put the code in the blank window that appears on the right of the screen.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("D:D,H:H,K:K"), Target) Is Nothing Then
        Application.EnableEvents = False
        Dim OldVal As String, NewVal As String
        NewVal = Target.Value
        Application.Undo
        OldVal = Target.Value
        If OldVal <> "" And Target.Row > 2 Then
            Target.Value = NewVal
            Target.Font.Color = vbRed
        Else
            Target.Value = NewVal
        End If
        Application.EnableEvents = True
    End If
End Sub
This works beautifully!! thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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