I shall monitor the value of a robot in excel. Everytime the robot sends the value "1" to my computer (Switches between 1 and 0, because digital) which shows up in the cell A1 in excel, the value "3" shall be added in cell B1. Second time A1 changes to 1 the value shall be 6 in B1 etc.
The code below does just that, except that it adds the value 3 even when it switches FROM 1 TO 0. I only want it to switch when it changes FROM 0 TO 1.
Using Excel 2007
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A5")) Is Nothing Then Me.Range("B5").Value = Me.Range("B5").Value + 3