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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,863
Messages
5,834,046
Members
430,257
Latest member
Todor T

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