Test for presence of chart on active sheet

K

Katherine

I've written the following code to create a chart on the active sheet.


'Select the range of data to chart (using the value from FindLastUsedRow)
Range(Cells(2, 1), Cells(intLastRow, 7)).Select

'Create the chart
With ActiveSheet.ChartObjects.Add(Left:=100, Width:=375, Top:=75,
Height:=255).Chart
.SetSourceData Source:=ActiveSheet.Range(Cells(2, 1), Cells(intLastRow,
7))
.ChartType = xlColumnClustered
.Axes(xlValue).MajorUnit = 1
End With


Two questions....

1) How can I check for the presence of a chart on the active sheet? The idea
is that the user clicks the button to initially create and then update the
chart, and I figured deleting and redrawing it would be the way to do this. I
need to be able to check if the chart on that sheet has already been created
and, if so, delete it.

2) Can someone explain to me the units of measurement that decide
whereabouts in the sheet the chart is placed? I got the (Left:=100,
Width:=375, Top:=75, Height:=255) above from the macro recorder, which is all
well and good but I don't understand exactly how it works.

Any suggestions greatly appreciated :)
 
A

AA2e72E

1. if activesheet.chartobjects.count is zero, there are no charts.
2. the measurements are points: refer to the help file & search for 'Left
Property'
 
K

Katherine

AA2e72E said:
1. if activesheet.chartobjects.count is zero, there are no charts.
2. the measurements are points: refer to the help file & search for 'Left
Property'

Thanks, the activesheet.chartobjects.count is just what I needed.

As for 2) I'd already tried searching the help files (both excel help and
the vbe help) but hadn't come across any useful results. Nevermind, I'll keep
googling it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top