Type Mismatch With SetSourceData

Draperies

Board Regular
Joined
Jun 29, 2009
Messages
79
I have a macro that takes my excel tables, opens up powerpoint, creates a new chart, and pulls in the data from the excel tables. I however receive a "Type Mismatch" error when I try to set the source data. Can anyone point me in the right direction? Here is some of the code:

Code:
        pptPrs.Slides.AddSlide pptPrs.Slides.count + 1, pptPrs.SlideMaster.CustomLayouts(slType)
        pptPrs.Slides(pptPrs.Slides.count).Select
        Set pptChrtObj = pptPrs.Slides(pptPrs.Slides.count).Shapes.AddChart.Chart
        Set pptChrtData = pptChrtObj.ChartData
        Set pptChrtWB = pptChrtData.Workbook
        Set pptChrtWS = pptChrtWB.Worksheets(1)

        With pptChrtObj
            .ChartType = chrtType
            .ChartArea.Font.Name = "Arial"
            .ChartArea.Font.Size = fontSz#
            .ChartArea.Font.Name = False
            .ChartArea.AutoScaleFont = False
            .Axes(xlCategory).HasMajorGridlines = False
            .Axes(xlValue).HasMajorGridlines = False
            .Axes(xlValue).MaximumScale = 100
            Do Until .SeriesCollection.count = 0
                .SeriesCollection(1).Delete
            Loop

            With .ChartData.Workbook.Sheets(1)
                .Cells.Clear
        ' Lengthy code that inserts certain data from initial excel workbook into the chart dataset
    End With

            For a = 2 To Range("A2").End(xlToRight).Column
                With .SeriesCollection.NewSeries
                    .Name = Cells(1, a)
                    .Values = Range(Cells(2, a), Cells(Range("A2").End(xlDown).Row, a)).Select
                End With
            Next
            .SetSourceData Source:=Range(Cells(1, 1), Cells(Range("A2").End(xlDown).Row, Range("B2").End(xlToRight).Column))
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
ActiveChart.SetSourceData Source:=Range(Cells(1, 1), Cells(Range("A2").End(xlDown).Row, Range("B2").End(xlToRight).Column))
HTH. Dave
 
Upvote 0
Thank you, although that now gives me the following error for that line: "Object variable or With block variable not set".
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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