PDA

View Full Version : Blinking Cells when I reach a certain value



Beegee
12-28-2020, 09:21 AM
Can I make a cell blink when I reach a certain value.

I want to use this macro in a billiards counting table.
When the player has reached his number of points, his points should flash on the scoreboard.

Who wants and can help me with this

david000
12-28-2020, 10:56 AM
From the late Chip Pearson 2006


Public RunWhen As Double

Sub StartBlink()
If Range("A1").Font.ColorIndex = 2 Then
Range("A1").Font.ColorIndex = xlColorIndexAutomatic
Else
Range("A1").Font.ColorIndex = 2
End If
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "StartBlink", , True
End Sub

Sub StopBlink()
Range("A1").Font.ColorIndex = xlColorIndexAutomatic
Application.OnTime RunWhen, "StartBlink", , False
End Sub

Paul_Hossler
12-28-2020, 05:59 PM
Here's one way

I made it so a number of cells are checked to see it the cell value is >= some thresh hold ( the array A)




Option Explicit


Public RunAgain As Double
Public RunNoMore As Boolean
Public A As Variant


Sub BlinkingStart()

RunNoMore = False



'A = pair = range to check, thresh hold to go larger
With Worksheets("Sheet1")
A = Array(.Range("A1"), 0, .Range("B2"), 2, .Range("C3"), 4, .Range("D4"), 6)
End With

Call Blink

End Sub






Sub Blink()
Dim i As Long

RunAgain = Now + TimeSerial(0, 0, 1)
Application.StatusBar = "Blink at " & Format(RunAgain, "Long Time")

For i = LBound(A) To UBound(A) - 1 Step 2
If IsEmpty(A(i)) Then
A(i).Interior.ColorIndex = xlColorIndexAutomatic
A(i).Font.ColorIndex = xlAutomatic

ElseIf A(i).Value >= A(i + 1) Then
If A(i).Interior.Color = vbRed Then
A(i).Interior.Color = vbGreen
A(i).Font.Color = vbBlack
ElseIf A(i).Interior.Color = vbGreen Then
A(i).Interior.Color = vbRed
A(i).Font.Color = vbWhite
Else
A(i).Interior.Color = vbGreen
A(i).Font.ColorIndex = vbBlack
End If

Else
A(i).Interior.ColorIndex = xlColorIndexAutomatic
A(i).Font.ColorIndex = xlAutomatic
End If

Next i

If RunNoMore Then Exit Sub

Application.OnTime RunAgain, "Blink", , True
End Sub


Sub BlinkingStop()
Dim i As Long

RunNoMore = True

On Error Resume Next
Application.OnTime RunAgain, "Blink", , False
On Error GoTo 0

For i = LBound(A) To UBound(A) - 1 Step 2
A(i).Interior.ColorIndex = xlColorIndexAutomatic
A(i).Font.ColorIndex = xlAutomatic
Next i


Application.StatusBar = False
End Sub

Beegee
12-29-2020, 11:32 AM
Thank you for the solution.
I am now going to see if just works for me.

Beegee
12-29-2020, 11:37 AM
David,
I think you have not understood my question, it should flash when a certain value is reached. A button in your solution is not the intention, then I have to switch it on and off manually.