I am animating a chard on sheet1 with data obtained from sheet2. The chart reads cells B8:P8 on sheet 1 and these cells are updated in a for loop in my VBA code and followed by "DoEvents" so that my chart updates, this event is triggered by a button click which sets a boolean "ss" to true and starts the while loop in which the for loop sits:
The bool "ss" is declared at the start of the code using
This works fine, I mean that when I press the button, the animation starts but when I press it again, it does not stop. Could someone please help me come up with a solution for stopping this.
Code:
Private Sub CommandButton2_Click()
ss = Not (ss)
Dim delt As Double, TotalT As Double
Dim NumberofTimeSteps As Integer, i As Integer, j As Integer
delt = Worksheets(1).Range("H4").Offset(0, 0).Value
TotalT = Worksheets(1).Range("I4").Offset(0, 0).Value
NumberofTimeSteps = TotalT / delt
Do While ss = True
DoEvents
For i = 1 + 1 To NumberofTimeSteps + 1
For j = 0 To 14
Worksheets(1).Cells(8, 2 + j).Offset(0, 0).Value = Worksheets(2).Cells(i, 2 + j).Offset(0, 0).Value
DoEvents
Next j
Next i
Loop
End Sub
Code:
Dim ss As Boolean