How to resize a bar chart using VBA

LeanidTerbant

New Member
Joined
Nov 15, 2010
Messages
16
I have created a macro for copying a bar chart from one sheet to another. I need to be able to resize the chart on the second sheet so that takes up more cells than it did on the other sheet. Is this possible using VBA?

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi

This is an example.

You have a chart called "Chart 1" in Sheet1. You want to copy it to Sheet2 and there you want to resize it so that it overlaps the range C3:M20.

Try:

Code:
Sub CopyChart()
Dim wsSrc As Worksheet, wsDest As Worksheet
Dim chtO As ChartObject
Dim r As Range
 
Set wsSrc = Worksheets("Sheet1")
Set wsDest = Worksheets("Sheet2")
Set r = wsDest.Range("C3:M20")
 
wsSrc.ChartObjects("Chart 1").Copy
wsDest.Paste
Set chtO = wsDest.ChartObjects(wsDest.ChartObjects.Count)
 
With chtO
    .Left = r.Left
    .Top = r.Top
    .Width = r.Width
    .Height = r.Height
End With
 
End Sub
 
Upvote 0
Hello everyone.
I have a few excel files, they are all the same but with different data in them, which generates different graphs in different sheets. What I want to do, is in a new Excel file, which I already have, have a macro that will go through every file in that folder and copy all Chart1 of each workbook and paste and resize them in sheet1 of the workbook with the macro, then copy all chart2 of each workbook and copy and paste/resize them in sheet2 of the file, and so on.

Is there a way I can do this with VBA? I really need some help! Thank you sooo much.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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