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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try like this

Code:
Set mychart = ws.ChartObjects("chart1")
With mychart.Chart
'do stuff here
End With
 
Upvote 0
Thanks for the quick reply. This gives me the error message:
'method or data member not found'
strange...
 
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,216,082
Messages
6,128,700
Members
449,464
Latest member
againofsoul

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