Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50319

Problems stopping chart animation with boolean

$
0
0
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:

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

The bool "ss" is declared at the start of the code using
Code:

Dim ss As Boolean
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.

Viewing all articles
Browse latest Browse all 50319

Latest Images

Trending Articles



Latest Images