Speeding up the Loop code.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
765
Hello friends, Hope all is well!

Please help me speed up the Loop code. The code is running OK; But too slow.

Thank you so much!


Code:
Sub B_REV()

Dim aSeries As Series
         ActiveSheet.ChartObjects("Chart 9").Select
    
    For Each aSeries In ActiveChart.SeriesCollection
        Select Case UCase(aSeries.Name)
        Case "REV"
        Case Else
            aSeries.Delete
            End Select
        Next aSeries
          
' Track elapsed time for procedure
    st = Now()
' Establish wait period - fraction of day
' Data Set
    num_rows = Sheet6.Range("A1").CurrentRegion.Rows.Count - 1
' Establish new series for last point on trend line
        ActiveChart.SeriesCollection.NewSeries
                ActiveChart.SeriesCollection(2).XValues = Sheets("REV").Cells(2, 1)
                ActiveChart.SeriesCollection(2).Values = Sheets("REV").Cells(2, 2)
' Loop through source data, copy to dynamic chart range
 For r = 2 To num_rows
     Sheets("REV").Cells(r, 4) = Sheets("REV").Cells(r, 1)
    Sheets("REV").Cells(r, 5) = Sheets("REV").Cells(r, 2)
    ActiveChart.SeriesCollection(2).XValues = Sheets("REV").Cells(r, 4)
    ActiveChart.SeriesCollection(2).Values = Sheets("REV").Cells(r, 5)
    ' Check to see if user wants animated chart
            If Sheets("chart").Range("AJ1") = "True" Then
            Application.Wait (Now + TimeValue("0:00:02") / 2)
        End If
    Next r
' Remove trend point series
        ActiveChart.SeriesCollection(2).Delete
 Range("a1").Select
End Sub
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Which loop is slowing things down?
 
Upvote 0
If that's what's slowing down the code why not remove it?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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