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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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