PC Review


Reply
Thread Tools Rate Thread

Deleting a sheet with the same name

 
 
LabrGuy Bob R
Guest
Posts: n/a
 
      5th Oct 2007
Hello, I have this listed in my code and it works fine when I remember to
delete the sheet and it can be replaced. However there are times I don't
succeed in getting to that place and hope I can get an answer.

If the "Rejected Voucher Statistaics" sheet exists I need to delete the
sheet from the workbook so the new "Pivot Table Sheet" can be moved
seemlessly and named the same. I would like to
1. Iheck and see if it exists
2. If it doesn't continue
3. If it does exist, delete it and continue with the macro..

ActiveSheet.Name = "Rejected Voucher Statistics"

Thanks BOBR


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Oct 2007
Sub test1()

For Each wks In Worksheets

If wks.Name = "Rejected Voucher Statistics" Then
wks.Delete
End If
Next wks

End Sub

"LabrGuy Bob R" wrote:

> Hello, I have this listed in my code and it works fine when I remember to
> delete the sheet and it can be replaced. However there are times I don't
> succeed in getting to that place and hope I can get an answer.
>
> If the "Rejected Voucher Statistaics" sheet exists I need to delete the
> sheet from the workbook so the new "Pivot Table Sheet" can be moved
> seemlessly and named the same. I would like to
> 1. Iheck and see if it exists
> 2. If it doesn't continue
> 3. If it does exist, delete it and continue with the macro..
>
> ActiveSheet.Name = "Rejected Voucher Statistics"
>
> Thanks BOBR
>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      5th Oct 2007
No need to loop

Application.DisplayAlerts = False
On Error Resume Next
Worksheets("Rejected Voucher Statistics").Delete
On Error GoTo 0
Application.DisplayAlerts = True




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Joel" <(E-Mail Removed)> wrote in message
news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
> Sub test1()
>
> For Each wks In Worksheets
>
> If wks.Name = "Rejected Voucher Statistics" Then
> wks.Delete
> End If
> Next wks
>
> End Sub
>
> "LabrGuy Bob R" wrote:
>
>> Hello, I have this listed in my code and it works fine when I remember to
>> delete the sheet and it can be replaced. However there are times I don't
>> succeed in getting to that place and hope I can get an answer.
>>
>> If the "Rejected Voucher Statistaics" sheet exists I need to delete the
>> sheet from the workbook so the new "Pivot Table Sheet" can be moved
>> seemlessly and named the same. I would like to
>> 1. Iheck and see if it exists
>> 2. If it doesn't continue
>> 3. If it does exist, delete it and continue with the macro..
>>
>> ActiveSheet.Name = "Rejected Voucher Statistics"
>>
>> Thanks BOBR
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Oct 2007
Errors should be reserved for Errors, not in place of good programming
practices. Good programming practrices should not force an error on a normal
condition. Errors should be reserved for abnormal condtions.

"Bob Phillips" wrote:

> No need to loop
>
> Application.DisplayAlerts = False
> On Error Resume Next
> Worksheets("Rejected Voucher Statistics").Delete
> On Error GoTo 0
> Application.DisplayAlerts = True
>
>
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Joel" <(E-Mail Removed)> wrote in message
> news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
> > Sub test1()
> >
> > For Each wks In Worksheets
> >
> > If wks.Name = "Rejected Voucher Statistics" Then
> > wks.Delete
> > End If
> > Next wks
> >
> > End Sub
> >
> > "LabrGuy Bob R" wrote:
> >
> >> Hello, I have this listed in my code and it works fine when I remember to
> >> delete the sheet and it can be replaced. However there are times I don't
> >> succeed in getting to that place and hope I can get an answer.
> >>
> >> If the "Rejected Voucher Statistaics" sheet exists I need to delete the
> >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
> >> seemlessly and named the same. I would like to
> >> 1. Iheck and see if it exists
> >> 2. If it doesn't continue
> >> 3. If it does exist, delete it and continue with the macro..
> >>
> >> ActiveSheet.Name = "Rejected Voucher Statistics"
> >>
> >> Thanks BOBR
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      5th Oct 2007
Don't be silly!

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Joel" <(E-Mail Removed)> wrote in message
newsE197322-DC41-4F28-9D20-(E-Mail Removed)...
> Errors should be reserved for Errors, not in place of good programming
> practices. Good programming practrices should not force an error on a
> normal
> condition. Errors should be reserved for abnormal condtions.
>
> "Bob Phillips" wrote:
>
>> No need to loop
>>
>> Application.DisplayAlerts = False
>> On Error Resume Next
>> Worksheets("Rejected Voucher Statistics").Delete
>> On Error GoTo 0
>> Application.DisplayAlerts = True
>>
>>
>>
>>
>> --
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>> "Joel" <(E-Mail Removed)> wrote in message
>> news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
>> > Sub test1()
>> >
>> > For Each wks In Worksheets
>> >
>> > If wks.Name = "Rejected Voucher Statistics" Then
>> > wks.Delete
>> > End If
>> > Next wks
>> >
>> > End Sub
>> >
>> > "LabrGuy Bob R" wrote:
>> >
>> >> Hello, I have this listed in my code and it works fine when I remember
>> >> to
>> >> delete the sheet and it can be replaced. However there are times I
>> >> don't
>> >> succeed in getting to that place and hope I can get an answer.
>> >>
>> >> If the "Rejected Voucher Statistaics" sheet exists I need to delete
>> >> the
>> >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
>> >> seemlessly and named the same. I would like to
>> >> 1. Iheck and see if it exists
>> >> 2. If it doesn't continue
>> >> 3. If it does exist, delete it and continue with the macro..
>> >>
>> >> ActiveSheet.Name = "Rejected Voucher Statistics"
>> >>
>> >> Thanks BOBR
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Oct 2007
I have a Master in Computer Science and havve been working for over 25 years.
I'm serious about GOOD Programming Practices!

"Bob Phillips" wrote:

> Don't be silly!
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Joel" <(E-Mail Removed)> wrote in message
> newsE197322-DC41-4F28-9D20-(E-Mail Removed)...
> > Errors should be reserved for Errors, not in place of good programming
> > practices. Good programming practrices should not force an error on a
> > normal
> > condition. Errors should be reserved for abnormal condtions.
> >
> > "Bob Phillips" wrote:
> >
> >> No need to loop
> >>
> >> Application.DisplayAlerts = False
> >> On Error Resume Next
> >> Worksheets("Rejected Voucher Statistics").Delete
> >> On Error GoTo 0
> >> Application.DisplayAlerts = True
> >>
> >>
> >>
> >>
> >> --
> >> HTH
> >>
> >> Bob
> >>
> >> (there's no email, no snail mail, but somewhere should be gmail in my
> >> addy)
> >>
> >> "Joel" <(E-Mail Removed)> wrote in message
> >> news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
> >> > Sub test1()
> >> >
> >> > For Each wks In Worksheets
> >> >
> >> > If wks.Name = "Rejected Voucher Statistics" Then
> >> > wks.Delete
> >> > End If
> >> > Next wks
> >> >
> >> > End Sub
> >> >
> >> > "LabrGuy Bob R" wrote:
> >> >
> >> >> Hello, I have this listed in my code and it works fine when I remember
> >> >> to
> >> >> delete the sheet and it can be replaced. However there are times I
> >> >> don't
> >> >> succeed in getting to that place and hope I can get an answer.
> >> >>
> >> >> If the "Rejected Voucher Statistaics" sheet exists I need to delete
> >> >> the
> >> >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
> >> >> seemlessly and named the same. I would like to
> >> >> 1. Iheck and see if it exists
> >> >> 2. If it doesn't continue
> >> >> 3. If it does exist, delete it and continue with the macro..
> >> >>
> >> >> ActiveSheet.Name = "Rejected Voucher Statistics"
> >> >>
> >> >> Thanks BOBR
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      5th Oct 2007
i have no such credentials, and i generally agree. but there are times using an
error to your advantage just makes sense. for example, when adding elements to a
collection. bob's example looks pretty benign to me, too.

--


Gary


"Joel" <(E-Mail Removed)> wrote in message
news:5F9F0417-227C-42CB-AA37-(E-Mail Removed)...
>I have a Master in Computer Science and havve been working for over 25 years.
> I'm serious about GOOD Programming Practices!
>
> "Bob Phillips" wrote:
>
>> Don't be silly!
>>
>> --
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>>
>> "Joel" <(E-Mail Removed)> wrote in message
>> newsE197322-DC41-4F28-9D20-(E-Mail Removed)...
>> > Errors should be reserved for Errors, not in place of good programming
>> > practices. Good programming practrices should not force an error on a
>> > normal
>> > condition. Errors should be reserved for abnormal condtions.
>> >
>> > "Bob Phillips" wrote:
>> >
>> >> No need to loop
>> >>
>> >> Application.DisplayAlerts = False
>> >> On Error Resume Next
>> >> Worksheets("Rejected Voucher Statistics").Delete
>> >> On Error GoTo 0
>> >> Application.DisplayAlerts = True
>> >>
>> >>
>> >>
>> >>
>> >> --
>> >> HTH
>> >>
>> >> Bob
>> >>
>> >> (there's no email, no snail mail, but somewhere should be gmail in my
>> >> addy)
>> >>
>> >> "Joel" <(E-Mail Removed)> wrote in message
>> >> news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
>> >> > Sub test1()
>> >> >
>> >> > For Each wks In Worksheets
>> >> >
>> >> > If wks.Name = "Rejected Voucher Statistics" Then
>> >> > wks.Delete
>> >> > End If
>> >> > Next wks
>> >> >
>> >> > End Sub
>> >> >
>> >> > "LabrGuy Bob R" wrote:
>> >> >
>> >> >> Hello, I have this listed in my code and it works fine when I remember
>> >> >> to
>> >> >> delete the sheet and it can be replaced. However there are times I
>> >> >> don't
>> >> >> succeed in getting to that place and hope I can get an answer.
>> >> >>
>> >> >> If the "Rejected Voucher Statistaics" sheet exists I need to delete
>> >> >> the
>> >> >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
>> >> >> seemlessly and named the same. I would like to
>> >> >> 1. Iheck and see if it exists
>> >> >> 2. If it doesn't continue
>> >> >> 3. If it does exist, delete it and continue with the macro..
>> >> >>
>> >> >> ActiveSheet.Name = "Rejected Voucher Statistics"
>> >> >>
>> >> >> Thanks BOBR
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Q2hhcmxpZQ==?=
Guest
Posts: n/a
 
      5th Oct 2007
Not true. I do it all the time for simplicity sake. Never had a problem.
I'm with Bob.

P.S. See the "On Error GoTo 0" line? That resets it for abnormal error
catching.

"Joel" wrote:

> Errors should be reserved for Errors, not in place of good programming
> practices. Good programming practrices should not force an error on a normal
> condition. Errors should be reserved for abnormal condtions.
>
> "Bob Phillips" wrote:
>
> > No need to loop
> >
> > Application.DisplayAlerts = False
> > On Error Resume Next
> > Worksheets("Rejected Voucher Statistics").Delete
> > On Error GoTo 0
> > Application.DisplayAlerts = True
> >
> >
> >
> >
> > --
> > HTH
> >
> > Bob
> >
> > (there's no email, no snail mail, but somewhere should be gmail in my addy)
> >
> > "Joel" <(E-Mail Removed)> wrote in message
> > news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
> > > Sub test1()
> > >
> > > For Each wks In Worksheets
> > >
> > > If wks.Name = "Rejected Voucher Statistics" Then
> > > wks.Delete
> > > End If
> > > Next wks
> > >
> > > End Sub
> > >
> > > "LabrGuy Bob R" wrote:
> > >
> > >> Hello, I have this listed in my code and it works fine when I remember to
> > >> delete the sheet and it can be replaced. However there are times I don't
> > >> succeed in getting to that place and hope I can get an answer.
> > >>
> > >> If the "Rejected Voucher Statistaics" sheet exists I need to delete the
> > >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
> > >> seemlessly and named the same. I would like to
> > >> 1. Iheck and see if it exists
> > >> 2. If it doesn't continue
> > >> 3. If it does exist, delete it and continue with the macro..
> > >>
> > >> ActiveSheet.Name = "Rejected Voucher Statistics"
> > >>
> > >> Thanks BOBR
> > >>
> > >>
> > >>

> >
> >
> >

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      5th Oct 2007
Exactly Charlie. In my production apps I have a fully integrated pass-back
error handler, but I still use this technique for little checks like this,
and then immediately reset the error handler. Works for me; I subscribe to
pragmatism over dogma every day.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Charlie" <(E-Mail Removed)> wrote in message
news:9E0D46F3-AAA4-40F4-8E1A-(E-Mail Removed)...
> Not true. I do it all the time for simplicity sake. Never had a problem.
> I'm with Bob.
>
> P.S. See the "On Error GoTo 0" line? That resets it for abnormal error
> catching.
>
> "Joel" wrote:
>
>> Errors should be reserved for Errors, not in place of good programming
>> practices. Good programming practrices should not force an error on a
>> normal
>> condition. Errors should be reserved for abnormal condtions.
>>
>> "Bob Phillips" wrote:
>>
>> > No need to loop
>> >
>> > Application.DisplayAlerts = False
>> > On Error Resume Next
>> > Worksheets("Rejected Voucher Statistics").Delete
>> > On Error GoTo 0
>> > Application.DisplayAlerts = True
>> >
>> >
>> >
>> >
>> > --
>> > HTH
>> >
>> > Bob
>> >
>> > (there's no email, no snail mail, but somewhere should be gmail in my
>> > addy)
>> >
>> > "Joel" <(E-Mail Removed)> wrote in message
>> > news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
>> > > Sub test1()
>> > >
>> > > For Each wks In Worksheets
>> > >
>> > > If wks.Name = "Rejected Voucher Statistics" Then
>> > > wks.Delete
>> > > End If
>> > > Next wks
>> > >
>> > > End Sub
>> > >
>> > > "LabrGuy Bob R" wrote:
>> > >
>> > >> Hello, I have this listed in my code and it works fine when I
>> > >> remember to
>> > >> delete the sheet and it can be replaced. However there are times I
>> > >> don't
>> > >> succeed in getting to that place and hope I can get an answer.
>> > >>
>> > >> If the "Rejected Voucher Statistaics" sheet exists I need to delete
>> > >> the
>> > >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
>> > >> seemlessly and named the same. I would like to
>> > >> 1. Iheck and see if it exists
>> > >> 2. If it doesn't continue
>> > >> 3. If it does exist, delete it and continue with the macro..
>> > >>
>> > >> ActiveSheet.Name = "Rejected Voucher Statistics"
>> > >>
>> > >> Thanks BOBR
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >



 
Reply With Quote
 
LabrGuy Bob R
Guest
Posts: n/a
 
      5th Oct 2007
That was interesting, thank you so much for all the comments. With me trying
to learn vb with excel the different approaches certainly gave me some good
information.
Thanks again
BOB R

"Charlie" <(E-Mail Removed)> wrote in message
news:9E0D46F3-AAA4-40F4-8E1A-(E-Mail Removed)...
> Not true. I do it all the time for simplicity sake. Never had a problem.
> I'm with Bob.
>
> P.S. See the "On Error GoTo 0" line? That resets it for abnormal error
> catching.
>
> "Joel" wrote:
>
>> Errors should be reserved for Errors, not in place of good programming
>> practices. Good programming practrices should not force an error on a
>> normal
>> condition. Errors should be reserved for abnormal condtions.
>>
>> "Bob Phillips" wrote:
>>
>> > No need to loop
>> >
>> > Application.DisplayAlerts = False
>> > On Error Resume Next
>> > Worksheets("Rejected Voucher Statistics").Delete
>> > On Error GoTo 0
>> > Application.DisplayAlerts = True
>> >
>> >
>> >
>> >
>> > --
>> > HTH
>> >
>> > Bob
>> >
>> > (there's no email, no snail mail, but somewhere should be gmail in my
>> > addy)
>> >
>> > "Joel" <(E-Mail Removed)> wrote in message
>> > news:7CDB38D1-C978-4D44-8536-(E-Mail Removed)...
>> > > Sub test1()
>> > >
>> > > For Each wks In Worksheets
>> > >
>> > > If wks.Name = "Rejected Voucher Statistics" Then
>> > > wks.Delete
>> > > End If
>> > > Next wks
>> > >
>> > > End Sub
>> > >
>> > > "LabrGuy Bob R" wrote:
>> > >
>> > >> Hello, I have this listed in my code and it works fine when I
>> > >> remember to
>> > >> delete the sheet and it can be replaced. However there are times I
>> > >> don't
>> > >> succeed in getting to that place and hope I can get an answer.
>> > >>
>> > >> If the "Rejected Voucher Statistaics" sheet exists I need to delete
>> > >> the
>> > >> sheet from the workbook so the new "Pivot Table Sheet" can be moved
>> > >> seemlessly and named the same. I would like to
>> > >> 1. Iheck and see if it exists
>> > >> 2. If it doesn't continue
>> > >> 3. If it does exist, delete it and continue with the macro..
>> > >>
>> > >> ActiveSheet.Name = "Rejected Voucher Statistics"
>> > >>
>> > >> Thanks BOBR
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >



 
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
deleting sheet Seeker Microsoft Excel Programming 4 7th Jun 2009 12:09 PM
deleting rows from one sheet based on 2nd sheet =?Utf-8?B?bWFnb2xkMjAwNUBob3RtYWlsLmNvbQ==?= Microsoft Excel Discussion 1 6th Sep 2007 07:38 AM
Deleting sheet Brandi Microsoft Excel Programming 2 7th Oct 2004 09:31 PM
Deleting Sheet with VBA Bre-x Microsoft Excel Discussion 1 2nd Sep 2003 08:08 PM
Deleting a Sheet Abdul Salam Microsoft Excel Programming 1 29th Jul 2003 12:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:00 PM.