Chart Position with VBA

paddydive

Active Member
Joined
Jun 30, 2010
Messages
460
Hi,

I have recorded a macro which creat a Pia Chart. I hv also recorded location of the chart which is on sheet Main.

My requirement is that can i put the chart on Cell J22. is it possible.

below is my code :

charts.Add
Activechart.ChartType =xlPie
activechart.SetSourceData Source:=Sheets("Sheet4").Range("U83:V84")
activechart.Location where:=xlLocationAsObject, Name:="Main"
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
add:
Code:
With ActiveChart.Parent
    .Top = Range("J22").Top
    .Left = Range("J22").Left
    'include these lines to make it fit exactly on J22:
    '.Height = Range("J22").Height
    '.Width = Range("J22").Width
End With
 
Upvote 0
Yet another method...

Code:
    Dim rng As Range
    
    Set rng = Range("J22:P37") 'Area to put the chart in
    
    With Sheets("Main").ChartObjects.Add _
        (Left:=rng.Left, Width:=rng.Width, Top:=rng.Top, Height:=rng.Height)
        .Chart.SetSourceData Source:=Sheets("Sheet4").Range("U83:V84")
        .Chart.ChartType = xlPie
    End With
 
Upvote 0
Thanks AlphaFrog,

I found this quite lenthy method, might be because i m new to VBA coding and not familar with it.

But I appriciate it, you guys are doing a great job.

thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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