Excel VBA - Copy and paste chart

M3one

New Member
Joined
Jul 29, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,
I've been struggling with this piece of code. First I must say that I'm not an expert in VBA. I want to copy a chart that it's located in Sheets("Graficos") to a chart object (myChart), modify it and paste it into another sheet (Sheets("Informe")). This is the code that I'm working on but I'm not able to make it work:

VBA Code:
    Dim myChart(1 To 100) As Chart
    Dim chartNumber As Integer
    Dim IMC As Double   
    
    'Some code here
    
    ThisWorkbook.Sheets("Graficos").ChartObjects("Chart 2").Activate 'Para evitar error al crear la imagen
    ThisWorkbook.Sheets("Graficos").ChartObjects("Chart 2").Copy
    Set myChart(chartNumber) = ThisWorkbook.Sheets("Informe").Shapes.AddChart(xlLine).Chart
    myChart(chartNumber).ChartObjects.Paste 'THIS IS NOT WORKING'
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If we look at the documentation for Chart.Paste, you'll notice that it doesn't quite do what you want it to do. You should instead use Range.PasteSpecial or Worksheet.Paste, depending on if you want the paste to be linked to the original data or not. For example to copy chart from the current location to Q1 on Sheet 1,
VBA Code:
Sub CopyPasteChart()
    Me.ChartObjects("Chart 1").Copy
    Sheet1.Range("Q1").Select
    ActiveSheet.Paste
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,344
Members
449,219
Latest member
Smiqer

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