闪烁单元格的值,如果该值为0 [英] Blink the cell value, If the value is 0

查看:89
本文介绍了闪烁单元格的值,如果该值为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我的电池范围是A5..D25.在此范围内,我有很多值.
如果值在上述范围内为"0",则需要闪烁单元格值.

我有vba代码来闪烁范围,不表示值是什么.
但是我只需要闪烁范围为(A5..D20)的"0"值即可.

谁能帮我吗?

问候,
查尔斯

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

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


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

推荐答案

使用伪代码:
In pseudocode:
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


这篇关于闪烁单元格的值,如果该值为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆