Determine if a chart exists

M

Matt S

All,

I've been using the search feature, but haven't crossed over a situation
where someone needed to determine if a chart exists.

I am giving the user the ability to run a snippet of code over again if they
change something. It essentially will regraph everything. I want to first
delete the Chart it had previously made if there were one and then recreate
it.

Here is my code below. I have an error message with the first line. The
two arr* terms are arrays that have a defined name.

Set shtnme = Worksheets(arrFileList(FileNum) & "_" & arrLayers(LayerNum))
'Delete graph if already there cause user reran graphing tool
If Not shtnme Is Nothing Then
Sheets(shtnme).Delete
Else: End If
 
J

joel

ChartName = arrFileList(FileNum) & "_" & arrLayers(LayerNum)
Found = false
for each sht in worksheets
if sht.name = ChartName then
Found = true
exit for
end if
next sht
if found = true then
Sheets(ChartName).Delete
end if
 
M

Matt S

Thank you Joel!!

<3 Matt

joel said:
ChartName = arrFileList(FileNum) & "_" & arrLayers(LayerNum)
Found = false
for each sht in worksheets
if sht.name = ChartName then
Found = true
exit for
end if
next sht
if found = true then
Sheets(ChartName).Delete
end if
 
M

Matt S

Joel,

that went over the sheets in my workbook, but not the charts. Will
replacing "for each sht in worksheets" with "for each cht in charts" work?

Thanks,
Matt
 

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