Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have cell Range from A5..D25. Within the range I have many values.
I need to blink the cell value if the value is "0" within the said Range.

I have vba code to blink the range, doesn't mattar what value is.
But I need to blink only the value of "0" with the range (A5..D20).

Can anyone help me?

Regards,
charles
VB
Sub StartBlink()
With ThisWorkbook.Worksheets("Sheet1").Range("A5:D25").Font
    
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 2 ' White Text
Else
.ColorIndex = 3 ' Red Text
End If
Next
End With
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink"
'True
End Sub

VB
Sub StopBlink()
ThisWorkbook.Worksheets("Sheet1").Range("A5:D25").Font.ColorIndex = _
xlColorIndexAutomatic
Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", False
'False
End Sub

'Then, in the ThisWorkbook code module of the workbook, use code like:

Private Sub Workbook_Open()
StartBlink
End Sub
Posted
Updated 21-Mar-12 20:04pm
v3

1 solution

In pseudocode:
VB
For i = 5 to 25
   if Cell(i,ColNo).Value = 0 Then BlinkIt
   'or
   'if Range("A" & i).Value = 0 Then BlinkIt
Next


Welcome...

'start blinking ;) 
Sub StartBlink()

BlinkRange ThisWorkbook.Worksheets(1).Range("A5:A25"), 0, True

End Sub

'stop blinking ;)
Sub StopBlink()

BlinkRange ThisWorkbook.Worksheets(1).Range("A5:A25"), 0

End Sub

'input:
' - the range of cells 
' - value to be passed (where condotion)
' - value to start or stop schedule (blinking)
Sub BlinkRange(oRng As Range, cellValue As Variant, Optional bBlink As Boolean = False)
Dim c As Range, dRunWhen As Date

'for each cell in range of cells
For Each c In oRng.Cells
    'if cell value is equal to ...
    If c.Value = cellValue Then
        'change color of font red/white
        c.Font.ColorIndex = IIf(c.Font.ColorIndex = 3, 2, 3)
    Else
        'change to default color of font 
        c.Font.ColorIndex = xlColorIndexAutomatic
    End If
Next c

'period: 1 sec.
dRunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime EarliestTime:=dRunWhen, Procedure:="'" & ThisWorkbook.Name & "'!StartBlink", Schedule:=bBlink

End Sub
 
Share this answer
 
v2
Comments
ebincharles 21-Mar-12 0:48am    
Thank you, Thank you so much for your reply. I have attached my code which I am using now, But I failed when I try your code
with my code to run the result.

Can you help me?

Regards,
Charles
Maciej Los 21-Mar-12 11:04am    
Before i'll help you, please tell me why StartBlink and StopBlink calling different ranges?
ebincharles 21-Mar-12 11:37am    
I am sorry, The correct Range is A5..D25 for both StartBlink & StopBlink. I am mistaken. But I hope that is not my main error.
Thanking for your kind help to solve this.
Regards,
Charles P
Maciej Los 21-Mar-12 18:42pm    
Please see my answer after changes. Try my solution and rate it.
ebincharles 23-Mar-12 8:48am    
Thank you so much. It's working.
Once again Thank you.
Regards,
CHarles P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900