PC Review


Reply
Thread Tools Rate Thread

Check for Sheet

 
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      7th May 2007
I am copying a worksheet from an existing worksheet (in the same file) that
has been named ShtTransmissionDetail. When it is copied Excel creates a
sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
is then set to the name a user has keyed in the system by the user. I am
trying to check if this sheet exists, and if it does then delete it or copy
over it.

I have tried multiple different ways / syntax and received multiple
different errors (object doesn't exist, etc...) and can't get this to work.
Thanks.

Sub CheckIfSheetExists()

On Error Resume Next

Application.DisplayAlerts = False

If ShtTransmissionDetail1 Is Nothing Then

Else

ShtTransmissionDetail1.Delete

End If

End Sub
 
Reply With Quote
 
 
 
 
Corey
Guest
Posts: n/a
 
      7th May 2007
This worked for me:
Sub Button1_Click()
On Error Resume Next
Application.DisplayAlerts = False
If Sheets("Sheet1") Is Nothing Then
Exit Sub
Else
Sheets("Sheet1").Delete
End If
Application.DisplayAlerts = True
End Sub

"Troubled User" <(E-Mail Removed)> wrote in message
news:252F2CA7-F960-4924-8C62-(E-Mail Removed)...
I am copying a worksheet from an existing worksheet (in the same file) that
has been named ShtTransmissionDetail. When it is copied Excel creates a
sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
is then set to the name a user has keyed in the system by the user. I am
trying to check if this sheet exists, and if it does then delete it or copy
over it.

I have tried multiple different ways / syntax and received multiple
different errors (object doesn't exist, etc...) and can't get this to work.
Thanks.

Sub CheckIfSheetExists()

On Error Resume Next

Application.DisplayAlerts = False

If ShtTransmissionDetail1 Is Nothing Then

Else

ShtTransmissionDetail1.Delete

End If

End Sub


 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      7th May 2007
Something like this perhaps?

dim wks as worksheet

on error resume next
set wks = ShtTransmissionDetail1
on error goto 0

Application.DisplayAlerts = False
if not wks is nothing then wks.delete
Application.DisplayAlerts = true

--
HTH...

Jim Thomlinson


"Troubled User" wrote:

> I am copying a worksheet from an existing worksheet (in the same file) that
> has been named ShtTransmissionDetail. When it is copied Excel creates a
> sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
> is then set to the name a user has keyed in the system by the user. I am
> trying to check if this sheet exists, and if it does then delete it or copy
> over it.
>
> I have tried multiple different ways / syntax and received multiple
> different errors (object doesn't exist, etc...) and can't get this to work.
> Thanks.
>
> Sub CheckIfSheetExists()
>
> On Error Resume Next
>
> Application.DisplayAlerts = False
>
> If ShtTransmissionDetail1 Is Nothing Then
>
> Else
>
> ShtTransmissionDetail1.Delete
>
> End If
>
> End Sub

 
Reply With Quote
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      7th May 2007
Thanks. This seems to have helped. I still have something strange going on
as it is creating the sheet called ShtTransmissionDetail2 even though I have
deleted ShtTransmissionDetail1. Maybe the delete is not complete before I
re-add? Anyway, I can code around it (although it is not what I expected).
Thanks for your help!

"Jim Thomlinson" wrote:

> Something like this perhaps?
>
> dim wks as worksheet
>
> on error resume next
> set wks = ShtTransmissionDetail1
> on error goto 0
>
> Application.DisplayAlerts = False
> if not wks is nothing then wks.delete
> Application.DisplayAlerts = true
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Troubled User" wrote:
>
> > I am copying a worksheet from an existing worksheet (in the same file) that
> > has been named ShtTransmissionDetail. When it is copied Excel creates a
> > sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
> > is then set to the name a user has keyed in the system by the user. I am
> > trying to check if this sheet exists, and if it does then delete it or copy
> > over it.
> >
> > I have tried multiple different ways / syntax and received multiple
> > different errors (object doesn't exist, etc...) and can't get this to work.
> > Thanks.
> >
> > Sub CheckIfSheetExists()
> >
> > On Error Resume Next
> >
> > Application.DisplayAlerts = False
> >
> > If ShtTransmissionDetail1 Is Nothing Then
> >
> > Else
> >
> > ShtTransmissionDetail1.Delete
> >
> > End If
> >
> > End Sub

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      7th May 2007
The numbering of new sheets will not revert back to 1 until you close and
re-open the file. That is just the way it works...
--
HTH...

Jim Thomlinson


"Troubled User" wrote:

> Thanks. This seems to have helped. I still have something strange going on
> as it is creating the sheet called ShtTransmissionDetail2 even though I have
> deleted ShtTransmissionDetail1. Maybe the delete is not complete before I
> re-add? Anyway, I can code around it (although it is not what I expected).
> Thanks for your help!
>
> "Jim Thomlinson" wrote:
>
> > Something like this perhaps?
> >
> > dim wks as worksheet
> >
> > on error resume next
> > set wks = ShtTransmissionDetail1
> > on error goto 0
> >
> > Application.DisplayAlerts = False
> > if not wks is nothing then wks.delete
> > Application.DisplayAlerts = true
> >
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "Troubled User" wrote:
> >
> > > I am copying a worksheet from an existing worksheet (in the same file) that
> > > has been named ShtTransmissionDetail. When it is copied Excel creates a
> > > sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
> > > is then set to the name a user has keyed in the system by the user. I am
> > > trying to check if this sheet exists, and if it does then delete it or copy
> > > over it.
> > >
> > > I have tried multiple different ways / syntax and received multiple
> > > different errors (object doesn't exist, etc...) and can't get this to work.
> > > Thanks.
> > >
> > > Sub CheckIfSheetExists()
> > >
> > > On Error Resume Next
> > >
> > > Application.DisplayAlerts = False
> > >
> > > If ShtTransmissionDetail1 Is Nothing Then
> > >
> > > Else
> > >
> > > ShtTransmissionDetail1.Delete
> > >
> > > End If
> > >
> > > End Sub

 
Reply With Quote
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      7th May 2007
Jim,

That would have made sense to me, but it is now toggling between 1 and 2!

"Jim Thomlinson" wrote:

> The numbering of new sheets will not revert back to 1 until you close and
> re-open the file. That is just the way it works...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Troubled User" wrote:
>
> > Thanks. This seems to have helped. I still have something strange going on
> > as it is creating the sheet called ShtTransmissionDetail2 even though I have
> > deleted ShtTransmissionDetail1. Maybe the delete is not complete before I
> > re-add? Anyway, I can code around it (although it is not what I expected).
> > Thanks for your help!
> >
> > "Jim Thomlinson" wrote:
> >
> > > Something like this perhaps?
> > >
> > > dim wks as worksheet
> > >
> > > on error resume next
> > > set wks = ShtTransmissionDetail1
> > > on error goto 0
> > >
> > > Application.DisplayAlerts = False
> > > if not wks is nothing then wks.delete
> > > Application.DisplayAlerts = true
> > >
> > > --
> > > HTH...
> > >
> > > Jim Thomlinson
> > >
> > >
> > > "Troubled User" wrote:
> > >
> > > > I am copying a worksheet from an existing worksheet (in the same file) that
> > > > has been named ShtTransmissionDetail. When it is copied Excel creates a
> > > > sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
> > > > is then set to the name a user has keyed in the system by the user. I am
> > > > trying to check if this sheet exists, and if it does then delete it or copy
> > > > over it.
> > > >
> > > > I have tried multiple different ways / syntax and received multiple
> > > > different errors (object doesn't exist, etc...) and can't get this to work.
> > > > Thanks.
> > > >
> > > > Sub CheckIfSheetExists()
> > > >
> > > > On Error Resume Next
> > > >
> > > > Application.DisplayAlerts = False
> > > >
> > > > If ShtTransmissionDetail1 Is Nothing Then
> > > >
> > > > Else
> > > >
> > > > ShtTransmissionDetail1.Delete
> > > >
> > > > End If
> > > >
> > > > End Sub

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      8th May 2007
I have not looked into it too deeply but are you performing a save at some
point. That resets a bunch of things...
--
HTH...

Jim Thomlinson


"Troubled User" wrote:

> Jim,
>
> That would have made sense to me, but it is now toggling between 1 and 2!
>
> "Jim Thomlinson" wrote:
>
> > The numbering of new sheets will not revert back to 1 until you close and
> > re-open the file. That is just the way it works...
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "Troubled User" wrote:
> >
> > > Thanks. This seems to have helped. I still have something strange going on
> > > as it is creating the sheet called ShtTransmissionDetail2 even though I have
> > > deleted ShtTransmissionDetail1. Maybe the delete is not complete before I
> > > re-add? Anyway, I can code around it (although it is not what I expected).
> > > Thanks for your help!
> > >
> > > "Jim Thomlinson" wrote:
> > >
> > > > Something like this perhaps?
> > > >
> > > > dim wks as worksheet
> > > >
> > > > on error resume next
> > > > set wks = ShtTransmissionDetail1
> > > > on error goto 0
> > > >
> > > > Application.DisplayAlerts = False
> > > > if not wks is nothing then wks.delete
> > > > Application.DisplayAlerts = true
> > > >
> > > > --
> > > > HTH...
> > > >
> > > > Jim Thomlinson
> > > >
> > > >
> > > > "Troubled User" wrote:
> > > >
> > > > > I am copying a worksheet from an existing worksheet (in the same file) that
> > > > > has been named ShtTransmissionDetail. When it is copied Excel creates a
> > > > > sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
> > > > > is then set to the name a user has keyed in the system by the user. I am
> > > > > trying to check if this sheet exists, and if it does then delete it or copy
> > > > > over it.
> > > > >
> > > > > I have tried multiple different ways / syntax and received multiple
> > > > > different errors (object doesn't exist, etc...) and can't get this to work.
> > > > > Thanks.
> > > > >
> > > > > Sub CheckIfSheetExists()
> > > > >
> > > > > On Error Resume Next
> > > > >
> > > > > Application.DisplayAlerts = False
> > > > >
> > > > > If ShtTransmissionDetail1 Is Nothing Then
> > > > >
> > > > > Else
> > > > >
> > > > > ShtTransmissionDetail1.Delete
> > > > >
> > > > > End If
> > > > >
> > > > > End Sub

 
Reply With Quote
 
=?Utf-8?B?VHJvdWJsZWQgVXNlcg==?=
Guest
Posts: n/a
 
      8th May 2007
No save. It appears to serial always beginning at zero rather than at the
last created value.

Thanks for your help.


"Jim Thomlinson" wrote:

> I have not looked into it too deeply but are you performing a save at some
> point. That resets a bunch of things...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Troubled User" wrote:
>
> > Jim,
> >
> > That would have made sense to me, but it is now toggling between 1 and 2!
> >
> > "Jim Thomlinson" wrote:
> >
> > > The numbering of new sheets will not revert back to 1 until you close and
> > > re-open the file. That is just the way it works...
> > > --
> > > HTH...
> > >
> > > Jim Thomlinson
> > >
> > >
> > > "Troubled User" wrote:
> > >
> > > > Thanks. This seems to have helped. I still have something strange going on
> > > > as it is creating the sheet called ShtTransmissionDetail2 even though I have
> > > > deleted ShtTransmissionDetail1. Maybe the delete is not complete before I
> > > > re-add? Anyway, I can code around it (although it is not what I expected).
> > > > Thanks for your help!
> > > >
> > > > "Jim Thomlinson" wrote:
> > > >
> > > > > Something like this perhaps?
> > > > >
> > > > > dim wks as worksheet
> > > > >
> > > > > on error resume next
> > > > > set wks = ShtTransmissionDetail1
> > > > > on error goto 0
> > > > >
> > > > > Application.DisplayAlerts = False
> > > > > if not wks is nothing then wks.delete
> > > > > Application.DisplayAlerts = true
> > > > >
> > > > > --
> > > > > HTH...
> > > > >
> > > > > Jim Thomlinson
> > > > >
> > > > >
> > > > > "Troubled User" wrote:
> > > > >
> > > > > > I am copying a worksheet from an existing worksheet (in the same file) that
> > > > > > has been named ShtTransmissionDetail. When it is copied Excel creates a
> > > > > > sheet named ShtTransmissionDetail1. The tab name of ShtTransmissionDetail1
> > > > > > is then set to the name a user has keyed in the system by the user. I am
> > > > > > trying to check if this sheet exists, and if it does then delete it or copy
> > > > > > over it.
> > > > > >
> > > > > > I have tried multiple different ways / syntax and received multiple
> > > > > > different errors (object doesn't exist, etc...) and can't get this to work.
> > > > > > Thanks.
> > > > > >
> > > > > > Sub CheckIfSheetExists()
> > > > > >
> > > > > > On Error Resume Next
> > > > > >
> > > > > > Application.DisplayAlerts = False
> > > > > >
> > > > > > If ShtTransmissionDetail1 Is Nothing Then
> > > > > >
> > > > > > Else
> > > > > >
> > > > > > ShtTransmissionDetail1.Delete
> > > > > >
> > > > > > End If
> > > > > >
> > > > > > End Sub

 
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
Check Activesheet for chart sheet or work sheet =?Utf-8?B?TlNL?= Microsoft Excel Charting 1 17th Jul 2007 09:00 PM
Check if the first sheet is the selected sheet melody Microsoft Excel Programming 3 13th Sep 2006 07:46 PM
Enable check box in protected sheet + group check boxes =?Utf-8?B?RGV4eHRlcnI=?= Microsoft Excel Misc 4 2nd Aug 2006 12:00 PM
how to use sumif function to check date in 1 sheet is < 2 sheet =?Utf-8?B?QmhhcmF0IFNhYm9v?= Microsoft Excel Worksheet Functions 3 30th Dec 2005 07:10 AM
Check changes on a sheet Lorenzo Microsoft Excel Programming 3 7th Aug 2003 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.