Creating chart with VBA

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello all,

I can't seem to find this one. I tried the Application.wait, but not sure that will do it.

The routine below runs perfectly fine to draw the plots; however, is there a way to have one loop draw on the chart at a time instead of the entire loop running and then all the plots appear at the same time?

VBA Code:
Sub DrawChart()
    Dim i As Long
    With ActiveChart
        .ChartType = xlXYScatter
      For i = 1 To 9
        With .SeriesCollection.NewSeries
          .XValues = Cells(i + 1, 1)
          .Values = Cells(i + 1, 2)
        End With
        Application.Wait (Now + TimeValue("00:00:02"))
      Next i
    End With
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Interesting. This seems to do it. Dave
Code:
 Dim i As Long
    With Sheets("Sheet1").ChartObjects(1).Chart
        .ChartType = xlXYScatter
      For i = 1 To 9
        With .SeriesCollection.NewSeries
          .XValues = Cells(i + 1, 1)
          .Values = Cells(i + 1, 2)
        End With
        Application.Wait (Now + TimeValue("00:00:01"))
        DoEvents
        Application.Wait (Now + TimeValue("00:00:01"))
      DoEvents
      Next i
    End With
 
Upvote 0
Solution
I have no idea why the code works like that and I really wasn't sure if it would work for U the same as it did for me. Thanks for posting your outcome. Dave
 
Upvote 0
Hi again FryGirl. I had forgot some wisdom that Jon Peltier had provided. This code makes more sense to me and is likely more reliable across operating systems. I have a notion that the previous code may be dependent upon maybe both the cpu speed and/or XL version. HTH. Dave
ps. Thanks again Jon
Code:
Sub DrawChart()
 Dim i As Long, t As Double
    With Sheets("Sheet1").ChartObjects(1).Chart
        .ChartType = xlXYScatter
      For i = 1 To 9
        With .SeriesCollection.NewSeries
          .XValues = Cells(i + 1, 1)
          .Values = Cells(i + 1, 2)
        End With
'Jon's part
t = Timer
Do Until Timer - t > 1
  DoEvents
Loop
      Next i
    End With
End Sub
 
Upvote 0
Hi Dave,

Interestingly enough, I too ran across this somewhere else and have implemented it. Thank you for the follow-up.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top