Copy And Align PivotChart into a seperate sheet

Quentin S

New Member
Joined
Aug 4, 2014
Messages
1
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:banghead::
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:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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