Tag Archives: Piscar

VBA – How to blink a cell in Microsoft Excel

This tip may sounds weird, but, who we are to judge other people’s necessities? That has happened some time ago in our forum, where a user asked for a code which is capable to blink a cell in Excel through VBA code. Well, after some coding, here is the result.

Insert this code into your Worksheet code:

Private Sub Worksheet_Calculate()
  If Range("B1").Value > 0 Then
      Blink "A1"
      Range("A1").Interior.ColorIndex = 0
  End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
  Application.Run Me.CodeName & ".Worksheet_Calculate"
End Sub

And this code into a VBA module:

Sub Blink(cell As String)
  If Range(cell).Interior.ColorIndex = 6 Then
      Range(cell).Interior.ColorIndex = 0
      Range(cell).Interior.ColorIndex = 6
  End If
  Application.OnTime Now + 1 / 86400, "doagain"
End Sub
Sub DoAgain()
  Application.Run Sheets("SuaPlanilha").CodeName & ".Worksheet_Calculate" 'mude aqui no nome da planilha
End Sub

This code blinks the cell A1, if cell B1 is empty.