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
Next
startTimer
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
Else
.ColorIndex = 3
End If
End With
startTimer
End Sub
Sub endTimer()
Application.OnTime Now + TimeValue(“00:00:01”), “color_cells”, schedule:=False
End Sub
Further reading:

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

Leave a Reply

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