Hi All,
This is my first steps on VBA in Excel 2010 and I face a bit of a challenge, I hope someone will be able to help.
I am treating with data concerning different factories having different production lines. Per factory, I am displaying 33 pivots charts next to their respective Pivot tables, each one with a specific production line filter on the same source data (just like the Page field report but on a single worksheet).
As all the factories do not have the same number of lines and I need to be able to display everything just by changing my slicers, I keep all 33 PivotCharts open and they are filled only if the line (hence the Pivot Table) exist for the Factory and Data are entered.
Per factory, I need to be able to select the charts that do have data, copy them to another sheet and align them in order to be printable.
Here is the Code I came up with by adding internet sources; I think I am not that fare but I struggle with the last steps:
If someone sees anything that might help me, I would be very grateful.
Thanks!
This is my first steps on VBA in Excel 2010 and I face a bit of a challenge, I hope someone will be able to help.
I am treating with data concerning different factories having different production lines. Per factory, I am displaying 33 pivots charts next to their respective Pivot tables, each one with a specific production line filter on the same source data (just like the Page field report but on a single worksheet).
As all the factories do not have the same number of lines and I need to be able to display everything just by changing my slicers, I keep all 33 PivotCharts open and they are filled only if the line (hence the Pivot Table) exist for the Factory and Data are entered.
Per factory, I need to be able to select the charts that do have data, copy them to another sheet and align them in order to be printable.
Here is the Code I came up with by adding internet sources; I think I am not that fare but I struggle with the last steps:
Code:
Sub CopyAndAlignCharts()
Dim iChart As Long
Dim nCharts As Long
Dim dTop As Double
Dim dLeft As Double
Dim dHeight As Double
Dim dWidth As Double
Dim nColumns As Long
dTop = 75 ' top of first row of charts
dLeft = 100 ' left of first column of charts
dHeight = 225 ' height of all charts
dWidth = 375 ' width of all charts
nColumns = 3 ' number of columns of charts
nCharts = ActiveSheet.ChartObjects.Count
For iChart = 1 To nCharts
Do While Workshets("FAC&Graph").ChartObjects(iChart).SeriesCollection(1).Values <> ""
ActiveChart.ChartArea.Copy
Worksheets("Sheet1").Paste
Loop
Next
For iChart = 1 To nCharts
With Worksheets("Sheet1").ChartObjects(iChart)
.Height = dHeight
.Width = dWidth
.Top = dTop + Int((iChart - 1) / nColumns) * dHeight
.Left = dLeft + ((iChart - 1) Mod nColumns) * dWidth
End With
Next
End Sub
If someone sees anything that might help me, I would be very grateful.
Thanks!
Last edited: