Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default worksheets collection... find...

what function do i use to determine if a worksheet name already exists;

or should i use error trapping to catch an attempt at creating a redundant
worksheet name?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default worksheets collection... find...

You can error trap or use a function

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


This in you macro

If SheetExists("Master") = True Then....


Or

Sub sheettest()
Dim N As Long
On Error Resume Next
With ThisWorkbook.Worksheets
N = Len(.Item("Report").Name)
If N = 0 Then
'your code
End If
End With
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"mark kubicki" wrote in message ...
what function do i use to determine if a worksheet name already exists;

or should i use error trapping to catch an attempt at creating a redundant
worksheet name?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default worksheets collection... find...

proposedname = "Sheet1"
for each sh in worksheets
if lcase(sh.name) = lcase(proposedname) then
msgbox "Name is a duplicate"
exit for
end if
Next
End Sub

or you can error trap.

--
Regards,
Tom Ogilvy

"mark kubicki" wrote in message
...
what function do i use to determine if a worksheet name already exists;

or should i use error trapping to catch an attempt at creating a redundant
worksheet name?




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
Find value in more than 100 worksheets at once Alamgir Farooq Excel Worksheet Functions 2 January 15th 08 02:47 PM
Find sum across all worksheets Ang2459 Excel Worksheet Functions 3 April 6th 06 07:25 PM
How can you find how many worksheets in a workbook? JonM4 Excel Discussion (Misc queries) 4 May 9th 05 09:46 PM
Using a collection class to implement mutliple find/replace strings in cells Bill Hertzing Excel Programming 2 February 18th 04 01:42 AM
How to find the type of Sheet in Excel.Workbook.sheets collection Raj[_7_] Excel Programming 3 December 9th 03 10:48 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"