Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
If sheet exists, then...
Hi Jim, It doesnt like the first sheetexists command....? Regards D *** Sent via Developersdex http://www.developersdex.com *** |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sheet name already exists | Excel Discussion (Misc queries) | |||
Sheet Exists in another file? | Excel Programming | |||
check to see if sheet exists | Excel Programming | |||
How can I know if a sheet exists ? | Excel Programming | |||
Testing to see if a sheet name exists | Excel Programming |