Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet presence?


Hello,

is there code to verify wether a certain sheet say <sheets("nameS") is
present in an open workbook?


Some help is most welcome.

Thank you


--
Zurn
------------------------------------------------------------------------
Zurn's Profile: http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=520135

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Sheet presence?

not sure if this is the preferred way


Sub test()
On Error GoTo err
Worksheets("sname").Activate
goto cont
err:
MsgBox "sheet does not exist"
exit sub
cont:
'your code
End Sub
--


Gary


"Zurn" wrote in message
...

Hello,

is there code to verify wether a certain sheet say <sheets("nameS") is
present in an open workbook?


Some help is most welcome.

Thank you


--
Zurn
------------------------------------------------------------------------
Zurn's Profile:
http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=520135



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sheet presence?

Dim TestName as String
dim testWks as worksheet
testname = "NameS"

set testwks = nothing
on error resume next
set testwks = worksheets(testname)
on error goto 0

if testwks is nothing then
'not there
else
'it is there
end if

========
If you don't want to do the test inline, you could use this function from Chip
Pearson:

Function WorksheetExists(SheetName As Variant, _
Optional WhichBook As Workbook) As Boolean
'from Chip Pearson
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) 0)
End Function

'and you can use it like:
....
if worksheetexists("myname",activeworkbook) then
application.displayalerts = false
worksheets("Myname").delete
application.displayalerts = true
end if

Zurn wrote:

Hello,

is there code to verify wether a certain sheet say <sheets("nameS") is
present in an open workbook?

Some help is most welcome.

Thank you

--
Zurn
------------------------------------------------------------------------
Zurn's Profile: http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=520135


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Sheet presence?

You could try this...

Dim blnSheetExists as Boolean
dim intCount as integer
dim intTotal as integer

intcount = 1
intsheetexists = false
inttotal = activeworkbook.worksheets.count

do while intcount < inttotal
sheets(intcount).select
if activehseet.name = "nameS" then
blnsheetexists = true
end if

intcount = intcount + 1
loop

msgbox "the existence of sheet nameS is " & blnsheetexists

Haven't tested this, but it should be about right.


"Zurn" wrote:


Hello,

is there code to verify wether a certain sheet say <sheets("nameS") is
present in an open workbook?


Some help is most welcome.

Thank you


--
Zurn
------------------------------------------------------------------------
Zurn's Profile: http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=520135


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 301
Default Sheet presence?

Function SheetExists(shName As String) As Boolean
On Error Resume Next
SheetExists = Not Sheets(shName) Is Nothing
End Function

You can test the above with
if SheetExists("Herman") then...

Bob Umlas
Excel MVP

"Zurn" wrote in message
...

Hello,

is there code to verify wether a certain sheet say <sheets("nameS") is
present in an open workbook?


Some help is most welcome.

Thank you


--
Zurn
------------------------------------------------------------------------
Zurn's Profile:

http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=520135





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sheet presence?


Thanks everybody!

Works perfect...


--
Zurn
------------------------------------------------------------------------
Zurn's Profile: http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=520135

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
count the presence of a date as 1 WLWTNG Excel Worksheet Functions 2 January 10th 10 09:29 PM
please help me mark their presence. hirendra7158 Excel Worksheet Functions 3 March 13th 06 10:46 PM
count their presence hirendra7158 Excel Worksheet Functions 1 March 13th 06 08:41 PM
presence of SOMETHING in a range of cells MD Excel Programming 1 April 29th 05 05:05 PM
Test for presence of chart on active sheet Katherine Excel Programming 2 March 8th 05 01:07 PM


All times are GMT +1. The time now is 09:05 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"