2

As we all know,

Dim wkSheet as Worksheet
Set wkSheet = ActiveSheet

will make it so the active sheet is defined by wkSheet and you can do what you want with it using wkSheet

My question is, how do you do this with a chart?

You can use ActiveChart. to do almost anything you want with the chart.

However I seem unable to set the chart as a varible/object/shape (or what ever it needs to be)

3 Answers 3

5
Public Sub cht()

Dim v As Chart

Set v = ActiveChart

End Sub

This worked for me. Is there an active chart?

Sign up to request clarification or add additional context in comments.

4 Comments

The trick after what you've done is to set the Chart.Chartobject, which is where you get to the Series, etc.
@DougGlancy Other way round actually. Series etc belong to Chart, which may be contained in a Chartobject, unless it's a separate sheet.
@Rory, Woops. Right you are. Thanks.
Well I was sure I had tried that ... Seems not ... still thanks for giving me the right answer
1

If you needed to use the chartObject variable type you can do it this way

Dim wb As Workbook
Dim ws As Worksheet
Dim chrt As ChartObject

Set wb = ActiveWorkbook
Set ws = ActiveSheet

Set chrt = ws.ChartObjects(wb.ActiveChart.Parent.Name)

Comments

-1

Dim strTemp As String

ActiveSheet.Shapes.AddChart2(317, xlRadar).Select

strTemp = ActiveChart.Name

Debug.Print strTemp

End Sub

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.