Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
VBA - How can I stop timing code with the click of a shape button
Post Body

I 'm building a dashboard with animated charts displaying financial positions over time. The data for the chart changes based on a date value within a cell which has forecast to date/spend to date/total budget data pulled from a master sheet which uses a SUM/OFFSET/MATCH combination which corresponds to the month values.

I've written a macro which changes this date value based on a time interval and is started when a shape marked "start" is clicked. The Macro functions and the charts update periodically, but there's an issue with clicking the button again to stop the code running and it just loops indefinitely. I'm sure I'm close, I just can't work out where I've gone wrong. Any advice would be much appreciated on how I can get it to stop without a CTRL Break? I'm sure there's a more efficient way of running the code but it is functional. See Below.

Dim Stopped As Boolean
Dim i As Integer
Option Explicit

Sub ChartAnimator()

    If Range("A1") = "START" Then
        Range("A1") = "STOP"
        Stopped = False

        Do Until Stopped Or i = 10

For i = -1 To 10

DoEvents
DoEvents

  Application.Wait (Now   TimeValue("0:00:02"))
  Range("A18").Formula = "=EOMONTH(DATE(2018,4,1)," & i & ") 1" 'inserts 1st day of month, 
starting at Apr 18 to Mar 19
    DoEvents
    DoEvents

  Next i
  Loop

    Else
        Stopped = True
        Range("A1") = "START"
    End If


End Sub

Author
Account Strength
100%
Account Age
9 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,337
Link Karma
1,999
Comment Karma
6,090
Profile updated: 1 week ago
Posts updated: 10 months ago
47

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago