Search code examples
exceleventsworksheet-functionvba

Worksheet.Change Event in Excel in real time


Take as example the following code which should state whether the content of Cell A3 is greater or smaller than 0.25, where in Cell A3 we have a formula like RAND() whoch generates random numbers between 0 and 1.

Private Sub Worksheet_Change(ByVal Target As Range)

Calculate

   If Range("A3") > 0.25 Then

      Range("B3") = "greater than 0.25"

    Else: Range("B3") = "smaller than 0.25"

    End If

End Sub

How to make this Event conditions to be verified in continuous time?


Solution

  • What about using timer? this function calls each 1 second

    Sub Test()
    
       Calculate
    
       If Range("A3") > 0.25 Then
          Range("B3") = "greater than 0.25"
       Else 
          Range("B3") = "smaller than 0.25"
       End If
    
       Application.OnTime Now + TimeSerial(0, 0, 1), "Test"
    End Sub