I have a total of 10 charts on a worksheet, 5 being in SI units and the other 5 being in ANSI. Each are divided into two separate columns. The 5 ANSI charts are aligned vertically in column "F". The 5 SI charts are aligned vertically in column "O".
I want to copy only the charts in column "F".
How would I go about copying them all at one time?
I currently have them copied one at a time
Code:
wb.Sheets(w).ChartObjects("Chart 9").Chart.ChartArea.Copy
With ThisWorkbook.Worksheets("Plots")
.Activate
.Range( "F2").Select
.Pictures.Paste
End With
wb.Sheets(w).ChartObjects("Chart 13").Chart.ChartArea.Copy
With ThisWorkbook.Worksheets("Plots")
.Activate
.Range("F17").Select
.Pictures.Paste
End With
wb.Sheets(w).ChartObjects("Chart 14").Chart.ChartArea.Copy
With ThisWorkbook.Worksheets("Plots")
.Activate
.Range("F32").Select
.Pictures.Paste
End With
wb.Sheets(w).ChartObjects("Chart 15").Chart.ChartArea.Copy
With ThisWorkbook.Worksheets("Plots")
.Activate
.Range("F47").Select
.Pictures.Paste
End With
wb.Sheets(w).ChartObjects("Chart 16").Chart.ChartArea.Copy
With ThisWorkbook.Worksheets("Plots")
.Activate
.Range("F64").Select
.Pictures.Paste
End With
In a loop you could do:
Dim chartPasteRow as integer
chartPasteRow = 2
For each chartName in Array("Chart 9", "Chart 13", "Chart 14", "Chart 15", "Chart 16")
wb.Sheets(w).ChartObjects(chartName).Chart.ChartArea.Copy
ThisWorkbook.Worksheets("Plots").Range("F" & chartPasteRow).PasteSpecial xlPasteValues
chartPasteRow = chartPasteRow + 15
Next chartName
If you want to paste all charts without having to specify you could do something like:
Dim chartPasteRow as integer
chartPasteRow = 2
For each cht In wb.Sheets(w).ChartObjects
cht.Chart.ChartArea.Copy
ThisWorkbook.Worksheets("Plots").Range("F" & chartPasteRow).PasteSpecial xlPasteValues
chartPasteRow = chartPasteRow + 15
Next cht
This is making the assumption that each chart will get pasted every 15 rows.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.