Set statement for chart object in vba

fboehlandt

Active Member
Joined
Sep 9, 2008
Messages
334
Hi everyone,
is it possible to make changes to a chart without 'activate'? This may be a silly question but I wonder if the chart has to be selected to iinvoke changes. Something on the lines of

Code:
Dim wb As Workbook
Dim ws As Worksheet
Dim mychart as Chart
Set wb = ThisWorkbook
Set ws = wb.Sheet("Sheet1")
Set mychart = ws. ??? ("chart1")
With mychart
'do stuff here
End With

Thanks very much for your help
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try like this

Code:
Set mychart = ws.ChartObjects("chart1")
With mychart.Chart
'do stuff here
End With
 
Upvote 0
p.s. i verified that the chart is called 'chart1'. This is actually a type mismatch in the set statement (i.e. 'Chart 1' is not a chart!?)
 
Last edited:
Upvote 0
This works for me

Rich (BB code):
Sub btest()
Dim wb As Workbook
Dim ws As Worksheet
Dim mychart As ChartObject
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
Set mychart = ws.ChartObjects("Chart 1")
With mychart.Chart
'do stuff here
End With
End Sub
 
Upvote 0
Yes, the declaration as chartobject rather than chart did the trick. From there I could refer to chartobject.chart to manipulate the chart without selecting it. Many thanks :)
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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