Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Deleting a sheet with the same name

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Deleting a sheet with the same name

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Deleting a sheet with the same name

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" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Deleting a sheet with the same name

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" wrote in message
...
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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Deleting a sheet with the same name

Don't be silly!

--
HTH

Bob

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

"Joel" wrote in message
...
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" wrote in message
...
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










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Deleting a sheet with the same name

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" wrote in message
...
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" wrote in message
...
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









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Deleting a sheet with the same name

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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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











  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Deleting a sheet with the same name

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" wrote in message
...
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






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Deleting a sheet with the same name

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" wrote in message
...
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" wrote in message
...
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








  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Deleting a sheet with the same name

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" wrote in message
...
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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA for deleting a sheet Mike Excel Programming 3 November 22nd 05 08:02 PM
Deleting sheet Brandi[_2_] Excel Programming 2 October 7th 04 09:31 PM
Deleting a sheet P. Dileepan[_2_] Excel Programming 3 April 12th 04 10:34 AM
Deleting Sheet Tommi[_2_] Excel Programming 3 December 18th 03 05:28 PM
Deleting a Sheet Abdul Salam Excel Programming 1 July 29th 03 12:43 AM


All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"