PC Review


Reply
Thread Tools Rate Thread

Determine if a chart exists

 
 
Matt S
Guest
Posts: n/a
 
      1st May 2009
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
 
Reply With Quote
 
 
 
 
joel
Guest
Posts: n/a
 
      1st May 2009

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


"Matt S" wrote:

> 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

 
Reply With Quote
 
Matt S
Guest
Posts: n/a
 
      1st May 2009
Thank you Joel!!

<3 Matt

"joel" wrote:

>
> 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
>
>
> "Matt S" wrote:
>
> > 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

 
Reply With Quote
 
Matt S
Guest
Posts: n/a
 
      1st May 2009
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

"joel" wrote:

>
> 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
>
>
> "Matt S" wrote:
>
> > 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

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      1st May 2009
Yeah, didn't you try it?

- Jon
-------
Jon Peltier, Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
Advanced Excel Conference - June 17-18 2009 - Charting and Programming
http://peltiertech.com/Training/2009...00906ACNJ.html
_______


"Matt S" <(E-Mail Removed)> wrote in message
news:AF83BC57-B195-42AC-A52B-(E-Mail Removed)...
> 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
>
> "joel" wrote:
>
>>
>> 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
>>
>>
>> "Matt S" wrote:
>>
>> > 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine if Sub Exists Paige Microsoft Excel Programming 4 17th Mar 2009 10:44 PM
VBA:: determine if UDF exists? George Microsoft Excel Misc 1 7th May 2007 12:57 PM
Determine if a File Exists Connie Microsoft Excel Programming 1 8th Nov 2006 09:11 AM
Determine whether SQL Server exists _DD Microsoft ADO .NET 25 27th Sep 2006 05:45 PM
determine if value exists =?Utf-8?B?Z2VlYmVl?= Microsoft Excel Programming 2 19th Sep 2006 11:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:48 PM.