Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If sheet exists, then...



Hi there,

Im looking for some simple VB that says if sheet xyz exist, then select
sheet and delete it, or else call Macro 1.

Any ideas...

Thanks!!!!

Darin

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default If sheet exists, then...

if sheetexits("xyz") then
application.displayalerts = false
sheets("xyz").delete
application.displayalerts = true
else
call Macro1
end if

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Darin Kramer" wrote:



Hi there,

Im looking for some simple VB that says if sheet xyz exist, then select
sheet and delete it, or else call Macro 1.

Any ideas...

Thanks!!!!

Darin

*** Sent via Developersdex http://www.developersdex.com ***

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If sheet exists, then...


Hi Jim,

It doesnt like the first sheetexists command....?

Regards

D


*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default If sheet exists, then...

typo

if sheetexists("xyz") then
application.displayalerts = false
sheets("xyz").delete
application.displayalerts = true
else
call Macro1
end if


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Darin Kramer" wrote in message
...

Hi Jim,

It doesnt like the first sheetexists command....?

Regards

D


*** Sent via Developersdex http://www.developersdex.com ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default If sheet exists, then...

Sorry... There was a typo sheetexits to sheetexists

Sub Test()
if sheetexists("xyz") then
application.displayalerts = false
sheets("xyz").delete
application.displayalerts = true
else
call Macro1
end if
end sub

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function

--
HTH...

Jim Thomlinson


"Darin Kramer" wrote:


Hi Jim,

It doesnt like the first sheetexists command....?

Regards

D


*** Sent via Developersdex http://www.developersdex.com ***



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default If sheet exists, then...

A spelling error.

Sheetexits should be sheetexists.


Darin Kramer wrote:

Hi Jim,

It doesnt like the first sheetexists command....?

Regards

D

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If sheet exists, then...

Okay typo fixed. But now for some reason Excel is thinking that the
sheet doesnt exist and is going to the "Else", but I can see the sheet
exists... any ideas...?



*** Sent via Developersdex http://www.developersdex.com ***
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default If sheet exists, then...

It takes the correct path in both situations for me.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Darin Kramer" wrote in message
...
Okay typo fixed. But now for some reason Excel is thinking that the
sheet doesnt exist and is going to the "Else", but I can see the sheet
exists... any ideas...?



*** Sent via Developersdex http://www.developersdex.com ***



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default If sheet exists, then...

There's no need to select the sheet before deleting it
(and doing so "forgets" your current selection).

On Error Resume Next
Application.DisplayAlerts = False
ActiveWorkbook.Sheets("xyz").Delete
Application.DisplayAlerts = True
On Error Goto 0

Darin Kramer wrote:
Hi there,

Im looking for some simple VB that says if sheet xyz exist, then select
sheet and delete it, or else call Macro 1.

Any ideas...

Thanks!!!!

Darin

*** Sent via Developersdex http://www.developersdex.com ***


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default If sheet exists, then...

I'd guess a slight change in the spelling of the name.

I'd look for leading/trailing/embedded spaces.

Darin Kramer wrote:

Okay typo fixed. But now for some reason Excel is thinking that the
sheet doesnt exist and is going to the "Else", but I can see the sheet
exists... any ideas...?

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
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
Sheet name already exists eddie_zoom Excel Discussion (Misc queries) 1 March 11th 05 02:53 PM
Sheet Exists in another file? Utkarsh[_2_] Excel Programming 1 November 2nd 04 01:57 AM
check to see if sheet exists Wandering Mage Excel Programming 1 September 28th 04 07:53 PM
How can I know if a sheet exists ? Ben.C Excel Programming 3 December 29th 03 09:36 AM
Testing to see if a sheet name exists anita Excel Programming 1 September 4th 03 10:14 PM


All times are GMT +1. The time now is 01:07 AM.

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"