Creating charts in every worksheet

eurano

New Member
Joined
Sep 13, 2015
Messages
25
Hi
The code below runs EXTREMELY slow. Somebody know the reason?



Code:
Sub WorksheetLoop()


    Dim WS As Worksheet, co As Object


    For Each WS In ActiveWorkbook.Worksheets


        Set co = WS.Shapes.AddChart()


'        ActiveSheet.Range("P2:AB2153").Select


        'adjust to suit...
        co.Top = 105
        co.Left = 450
        co.Width = 900
        co.Height = 300


        With co.Chart
        
        
        
        .ChartType = xlLine


  Do Until .SeriesCollection.Count = 0
    .SeriesCollection(1).Delete
  Loop
  
  
  With .SeriesCollection.NewSeries
    .Name = "=""Temperatura"""
    .XValues = Range(Range("b2"), Range("b2").End(xlDown))
    .Values = Range(Range("a1"), Range("a2").End(xlDown))
  End With


With .SeriesCollection.NewSeries
    .Name = "=""Niedozwolona"""
    .XValues = Range(Range("b2"), Range("b2").End(xlDown))
    .Values = Range(Range("c1"), Range("c2").End(xlDown))
  End With


With .SeriesCollection.NewSeries
    .Name = "=""Niedopuszczalna"""
    .XValues = Range(Range("b2"), Range("b2").End(xlDown))
    .Values = Range(Range("d1"), Range("d2").End(xlDown))








End With
            
            
            
        
            
            
        End With


Set co = Nothing
        Debug.Print "Processed: " & WS.Name


    Next WS
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Well, there's apparently a lot of data in the chart when you start.

When you originally recorded your code, you had selected a large range, then you're not really using it. Instead, select something smaller, like "B1:C2".

Then you should clear the chart data before you set the chart type. In your code, you had all that data in the chart, then you changed the chart type and had to wait for Excel to redraw the chart one series at a time.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,205
Members
448,554
Latest member
Gleisner2

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