SOS Set SourceData Chart

Marissie

New Member
Joined
Jun 14, 2017
Messages
6
Hi everyone! How are you?
I am working on a financial report with +100 worksheets where I use a For Each loop to create charts on every worksheet.
I had one that worked excellent but now that I added some extra columns to the pivottable which I don't want to add into the chart, I had to change the sourcedata to get from column A and B instead using currentregion but can't make it work. It's probably a little detail or something but it's frustrating and hope someone can help me.
And maybe you also know how to name the charttitle on each sheet as mentioned in cell B1?
These are the lines of codes that I have now:

Sub CreateCharts()

Dim ws As Worksheet
Dim co As ChartObject

For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Inhoudsopgave" Then
Set co = ws.ChartObjects.Add(300, 30, 600, 300)
With co.Chart
.ChartType = xlColumnClustered
.SetSourceData ws.range("A3:B3").End(xlDown))
.ChartColor = 11
.HasTitle = True
.ChartTitle.Caption = "Monthly Sales 2017"
.ChartGroups(1).VaryByCategories = True
.ChartArea.RoundedCorners = True
.ChartArea.Shadow = True
End With

'Move chart
co.Left = ws.range("F3").Left
co.Top = ws.range("F3").Top
co.Width = ws.range("F3:P3").Width
co.Height = ws.range("F3:P22").Height

Set co = Nothing

End If

Next ws

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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