How to make Excel Worksheet Cells Flash with VBA

We can make Excel worksheet cells flash with VBA so that the user is reminded of the action he is supposed to take. Because the process of flashing or blinking involves a certain type of animation we need to use a timer to accomplish the process. Watch the training video before diving into the VBA code:

Watch this video on YouTube.

The complete VBA code to animate cells data in Excel:

Module 1 formats the cells and calls the Timer function startTimer:

Sub makeCellsFlash()
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim x As Long
lastrow = Sheets(“sheet1”).Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
mydate1 = Cells(x, 2).Value
mydate2 = mydate1
datetoday1 = Date
datetoday2 = datetoday1
If mydate2 – datetoday2 = 3 Then
Cells(x, 3) = “Yes”
Cells(x, 3).Interior.ColorIndex = 3
Cells(x, 3).Font.ColorIndex = 2
Cells(x, 3).Font.Bold = True
End If
End Sub
Module 2 contains the VBA code for the timer:
Sub startTimer()
Application.OnTime Now + TimeValue(“00:00:01”), “color_cells”
End Sub
Sub color_cells()
With ThisWorkbook.Worksheets(“sheet1”).Range(“C2:C6”).Font
If .ColorIndex = 3 Then
.ColorIndex = 2
.ColorIndex = 3
End If
End With
End Sub
Sub endTimer()
Application.OnTime Now + TimeValue(“00:00:01”), “color_cells”, schedule:=False
End Sub
Further reading:

Leave a Reply

Your email address will not be published. Required fields are marked *