crushing vba code

emantzoo

Board Regular
Joined
Nov 6, 2013
Messages
80
I do not know much about VBA, so I adapted the following sub to create a special graph.
Sometimes it runs ok but sometimes it crushes, giving an error message at the line with the asterisks.
Is it possible to make it fail-proof?


Thanxx!!

Code:
Sub MakePies()


   Sheets("Plots1").Select
      Sheets("Plots1").Activate


    Dim chtMarker As Chart
    Dim chtMain As Chart
    Dim intPoint As Integer
    Dim rngRow As Range
    Dim lngPointIndex As Long
    
     ActiveWorkbook.RefreshAll
    Sheets("Rslt-Pivots").Calculate
    Sheets("Plots1").Calculate
    
Application.ScreenUpdating = False
    Set chtMarker = Sheets("Plots1").ChartObjects("chtPieMarker1").Chart
    
    
    lngPointIndex = 0
    
    Sheets("Plots1").Activate
    
    Set chtMain = Sheets("Plots1").ChartObjects("graph3").Chart
    
    
    For Each rngRow In Sheets("Plots1").Range("Ae3:AN19").Rows
        chtMarker.SeriesCollection(1).Values = rngRow
        chtMarker.Parent.CopyPicture xlScreen, xlPicture
        lngPointIndex = lngPointIndex + 1
        chtMain.SeriesCollection(1).Points(lngPointIndex).Paste  *********
    Next
    
   
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Whoops. Maybe add...
Code:
Application.CutCopyMode = False
before the "next rngrow". HTH. Dave
ps. Don't U just end up with 1 series (the last rngrow) in your chart?
 
Upvote 0

Forum statistics

Threads
1,215,080
Messages
6,123,013
Members
449,093
Latest member
ikke

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