Totally New to Charts and use of VBA

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
I have the following code in a standard module. CreateChart creates a new embedded chart (let's say Chart 1) - the Only Chart on the SheetNamed Main.
CreateChart works fine.

Macro HideChart is not working - I only want to Hide the chart.

I need code to also Show the Chart when I run a macro (not shown)

This is a bit tough; Can someone assist? TIA, Jim

Code:
Dim ch As Chart

Sub CreateChart()
    CRow = ActiveCell.Row
    Set CRange = Application.Union(Range("B" & CRow), Range("C" & CRow), Range("M" & CRow))
    Set co = ActiveSheet.ChartObjects.Add(150, 150, 550, 365)
    Set ch = co.Chart
    ch.SetSourceData Source:=CRange
End Sub

Sub HideChart()
'ch.Visible = False
'ActiveSheet.ChartObjects(0).Visible = False
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hello,

I have used charting sparingly in VBA.

Try like:

<font face=Courier New>Sheet1.Shapes("Chart 3").Visible = <SPAN style="color:#00007F">True</SPAN></FONT>

-Jeff
 
Upvote 0
I have a single Chart (named MyChart) on my Worksheet Main (the Activesheet)
As I step thru the code (F8) I get a Rt error 9 (Subscript out of range) on line 3.
Can someone spot why? TIA, JIM

Sub BringUpChart()
Dim ch As Chart
Set ch = ActiveWorkbook.Charts("MyChart")
CRow = ActiveCell.Row
Set CRange = Application.Union(Range("B" & CRow), Range("C" & CRow), Range("M" & CRow))
ch.Visible = True
ch.SetSourceData Source:=CRange, PlotBy:=xlRows
End Sub
 
Upvote 0
Hello Jim,

Sorry for the delay, I have been on a learning curve.

Have you made any progress on this?

I did find this in the help file about charts that are embedded into the WS:

<TABLE id=topTable width="100%"><TBODY><TR id=headerTableRow2><TD align=left>
Charts Collection

</TD></TR></TBODY></TABLE>A collection of all the chart sheets in the specified or active workbook.

Remarks
Each chart sheet is represented by a Chart object. This does not include charts embedded on worksheets or dialog sheets. For information about embedded charts, see the Chart or ChartObject topics.



This seems to work:

Code:
Set ch = Worksheets(1).ChartObjects("MyChart")


Please post any results or other hang-ups with charts as I am interested in this and have been working on this at night. I have even saved a WB, usually I just close and don't save for MRExcel posts. :)


-Jeff
 
Upvote 0
Jeff - Thanks for the note;

Yes, I finally got things working. Unfortunately (based on my understanding), It could come "tumbling-down" -- at any time.

Jim
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,882
Members
452,948
Latest member
Dupuhini

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