Consulting

Results 1 to 3 of 3

Thread: Update chart after cell gets updated

  1. #1
    VBAX Regular
    Joined
    Jan 2009
    Posts
    89
    Location

    Update chart after cell gets updated

    Trying to find a way to have the chart update as macro is running. I can see the cells update each time B11 changes but can not get chart to update until marco finishes loop.

    Private Sub CommandButton1_Click()
    
        For x = 0 To 44
        Range("B11").Value = x
        Application.Wait (Now + TimeValue("00:00:03"))
        ActiveSheet.ChartObjects("Chart 3").Chart.Refresh
        Range("B11").Value = x + 1
        Next x
    
    
        
    End Sub

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    There are many differing thoughts on DoEvents, but it does work in instances like this, but for reliable updating I had to put it in 4 times!

    I changed the order of the code to update the chart before the wait command:

    Private Sub CommandButton1_Click()    Dim x As Long, dummy As Long
        For x = 0 To 5
        Range("B11").Value = x
        ActiveSheet.ChartObjects("Chart 3").Chart.Refresh
        DoEvents: DoEvents: DoEvents: DoEvents
        Application.Wait (Now + TimeValue("00:00:01"))
        Range("B11").Value = x + 1
        Next x
    
    
    
    
        
    End Sub
    There are probably better ways to do it, but I can't help there, sorry.
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Regular
    Joined
    Jan 2009
    Posts
    89
    Location
    Thank you for this, I do appreciate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •