ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If sheet exists, then... (https://www.excelbanter.com/excel-programming/372660-if-sheet-exists-then.html)

Darin Kramer

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 ***

Jim Thomlinson

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 ***


Darin Kramer

If sheet exists, then...
 

Hi Jim,

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

Regards

D


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

Bob Phillips

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 ***




Jim Thomlinson

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 ***


Dave Peterson

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

Darin Kramer

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 ***

Bob Phillips

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 ***




Andrew Taylor

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 ***



Dave Peterson

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


All times are GMT +1. The time now is 09:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com