VBA copy - paste bug?

Diogo Silva

New Member
Joined
Jun 8, 2020
Messages
3
Office Version
  1. 2013
Platform
  1. Windows
Hello everyone,

I came here because i have this problem that is driving me nuts. I can't find nothing similar on the internet (maybe because it's kind of hard to explain without images).

Here's the problem:
- I want to use a macro to copy a box plot graph from a sheet and paste it on another sheet using the following code (since i am running a for cycle i use some variables on the coordinates in the sheet):

Sheets(s + 4).Select
ActiveSheet.ChartObjects("Gráfico 9").Activate
Application.CutCopyMode = False
ActiveChart.ChartArea.Copy
Sheets("Print").Select
ActiveSheet.Cells(l + 22, 3).Select
ActiveSheet.Paste

- Using this code i obtain something like this:
Captura de Ecrã (30).png

As you can see, the "Cmin" value is in a very strange format (,320.0) as the value in the table is just 0,32.

- Once i Copy and Paste it manually, even after using the macro, i obtain the 0,32 on the graph.
- This also works if i just right-click then "select data" and just cancel without any modification.
- If I change the decimal cases shown on the table it comes back to normal too, but it would be too much work to change this format on every table.

Do you have any suggetions for solving this problem?

Thank you in advance for the attention.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi, are you ok?

Try:

VBA Code:
Sheets(s + 4).Select
ActiveSheet.ChartObjects("Gráfico 9").Activate
Application.CutCopyMode = False
ActiveChart.ChartArea.Copy
Sheets("Print").Select
ActiveSheet.Cells(l + 22, 3).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
 
Upvote 0
Hello Leandro,

Thank you for such a fast reply.

I tried your suggestion but it gives me 1004 error: "Not possible to execute paste special method from range class" ("Não foi possível executar o método PasteSpecial da classe Range")

Regards,
Diogo
 
Upvote 0
Desculpe Diogo, não vi que você é brasileiro.

Acho que podemos escrever em português.

A área copiada é do mesmo tamanho que o local onde você quer colar?
 
Upvote 0
Bom dia Leandro, não há qualquer problema, apesar de ser português irmão :)

Julgo que possa ser mais útil para um futuro utilizador se formos falando em inglês, mas é como preferir.

Para responder à sua pergunta: Não, o tamanho da imagem é ajustado posteriormente à colagem. No entanto, correndo a macro passo a passo verifico que o gráfico toma aquela forma logo após a colagem.

In english:

Leandro's question: "Is the image copied of the same size of the pasted one?"
My answer: No. The image size is adjusted after i paste, however, running the macro step by step i realize that the bug occurs after the pasting and not on the scaling.
 
Upvote 0
Bom dia Leandro, não há qualquer problema, apesar de ser português irmão :)

Julgo que possa ser mais útil para um futuro utilizador se formos falando em inglês, mas é como preferir.

Para responder à sua pergunta: Não, o tamanho da imagem é ajustado posteriormente à colagem. No entanto, correndo a macro passo a passo verifico que o gráfico toma aquela forma logo após a colagem.

In english:

Leandro's question: "Is the image copied of the same size of the pasted one?"
My answer: No. The image size is adjusted after i paste, however, running the macro step by step i realize that the bug occurs after the pasting and not on the scaling.

Boas Diogo!
Espero não tê-lo ofendido ao chamá-lo de brasileiro, de todo modo, como você disse somos irmãos, o avô de minha avó materna era português, mas não sei de qual zona e tenho um bom amigo em Portugal em Almeirim, o gajo é adepto do Glorioso!


When you maek this without macro, the chart stay correct?
Do you can post the complete macro?
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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