(Solved) – How to automaticaly run vba code after exit

(solved)-–-how-to-automaticaly-run-vba-code-after-exit

I have a excel which design for if the target value is not met H1 cell automatically blink.Can stop this vba code by entering 1 in D1 cell.But after I delete 1 from the D1 cell again it doest blink again until I run the macro by manually.
below is the code in Module

    Sub BlinkCell()
Dim CellToBlink As Range
Set CellToBlink = Range("H1")
Do While Range("F20").Value < Range("B1").Value
    CellToBlink.Interior.ColorIndex = 44
    Application.Wait (Now   TimeValue("0:00:01"))
    CellToBlink.Interior.ColorIndex = 0
    Application.Wait (Now   TimeValue("0:00:01"))
    CellToBlink.Interior.ColorIndex = 44
    DoEvents
If Range("D1").Value = 1 Then Exit Do

Loop

If Range("F20").Value >= Range("B1").Value Then
CellToBlink.Interior.Color = vbWhite
End If

End Sub

Below is the Code in worksheet

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B5:E19")) Is Nothing Then
Range("D1").ClearContents
Call BlinkCell
End If

End Sub

Image

Leave a Reply

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