Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default check for worksheets

How do I check to see if a worksheet already exists before creating it using
VBA?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default check for worksheets

I stole this 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

erlanr wrote:

How do I check to see if a worksheet already exists before creating it using
VBA?


--

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
Spell Check in Protected Worksheets Jae Excel Discussion (Misc queries) 3 February 9th 07 10:14 PM
check register with multiple worksheets jerikthegreat Excel Discussion (Misc queries) 1 January 24th 07 07:27 PM
How do I check for duplicates across multiple worksheets Chrissy Excel Worksheet Functions 2 July 29th 06 06:34 PM
Allowing spell check on protected worksheets Allowing spell check on protected worksh Setting up and Configuration of Excel 1 February 8th 05 07:13 PM
need check two worksheets to lookup a value Clay Excel Discussion (Misc queries) 2 January 5th 05 08:35 AM


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