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
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