Selecting a chart in a worksheet

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
Hi everyone,

I'm looking for a way to select all the charts (or only one) on a worksheet in VB using its title/label?

I have tried Charts("Title").select, but this has not worked. I have recorded a macro, and the code generated is as follows:

ActiveSheet.ChartObjects("Chart 68").Activate
ActiveChart.ChartArea.Select
Selection.Delete

The Chart 68 bit is because I created 67 earlier charts (and deleted them; the latest being number 68.

Is there any way of using a less specific chart reference in the statement:

ActiveSheet.ChartObjects("Chart 68").Activate - like using "Title" instead of "Chart 68" in the brackets? My requirement is quite straight forward, I want to select any previously created charts in the worksheet and delete these, before creating a new chart. Of course, I could keep the same chart and change the data to be plotted, but selecting and deleting is more useful in my case.

Many thanks,

vcoder
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
This code will delete all charts on the active worksheet.
Code:
Sub DeleteAllCharts()
Dim ChObj As Object
    For Each ChObj In ActiveSheet.ChartObjects
        ChObj.Delete
    Next ChObj
End Sub
 

vbacoder

Active Member
Joined
Jul 7, 2007
Messages
354
Thank you Datsmart! I've run it and it works very well!!

Best wishes,

vcoder
 

Watch MrExcel Video

Forum statistics

Threads
1,122,601
Messages
5,597,117
Members
414,126
Latest member
jellevansoelen

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
Top