Copying Charts from Visible Sheets

antelitomf

New Member
Joined
Sep 18, 2015
Messages
1
Hello
Im trying to copy the charts from all the visible sheets from myworkbook and then organize them all in the worksheet.
I got it to work but for some reason it copies it all twice and I dont't know how to fix it. Could somebody please look at the code and help me out please.
Thanks!

ub charts()


Application.ScreenUpdating = False


Plan13.DrawingObjects.Select
Plan13.DrawingObjects.Delete


Dim sht As Worksheet
Dim cht As ChartObject



For Each sht In Worksheets
If sht.Visible = xlSheetVisible Then
sht.Activate
For Each cht In sht.ChartObjects

cht.Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
Plan13.Paste

Next cht

End If

Next sht

Dim numCols, chtWidth, chtHeight, chtGap, chtStartLeft, chtStartTop, resetLeft, chartCount As Integer




'configurable data follows


chtHeight = 240


chtWidth = 140


chtStartLeft = 60


chtStartTop = 5


chtGap = -5




numCols = 1


'end configurable data




chartCount = ActiveSheet.ChartObjects.Count




For i = 0 To chartCount - 1


'select the chart to process


Set cht = ActiveSheet.ChartObjects(i + 1)






'remainder of loop counter divided by number of columns gives column position


col = i Mod numCols


cht.Left = chtStartLeft + chtWidth * col + chtGap * col


'calculate using integer division to get row position


row = i \ numCols


cht.Top = chtStartTop + chtHeight * row + chtGap * row


Next





End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi
Welcome to the board

Looking at the code, maybe your Plan13 worksheet is after the other ones?

If that's the case, when the loop gets to Plan13, Plan13 has already all the charts in the other sheets and then you will copy them again into Plan13, resulting in 2 copies of each chart.

You should exclude worksheet Plan13 from the loop.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

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