LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Worksheets.Add --- IF it doesn't already exist

I'm looping through some workbooks in a directory, then adding new
sheets to my active workbook. How can I test to make sure a worksheet
doesnt exist before I add it? And if it does exist how do I activate
that sheet? Something like this maybe?


If ThisWorkbook.Worksheets < Left$(bk.Name, 3) Then
Set sh2 = ThisWorkbook.Worksheets.Add
sh2.Name = Left$(bk.Name, 3)

' Do stuff with sh2

Else
Set sh2 = Left$(bk.Name, 3)

' Do stuff with sh2

End If


Thanks,
-- Dan

 
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
How to check worksheets exist or not ? moonhk Excel Programming 0 November 16th 06 01:47 AM
How do linked worksheets exist with data on an external device tazzer Excel Worksheet Functions 0 August 5th 06 09:42 AM
Copy Worksheet to a new Workbook creating if it doesn't exist and add more Worksheets if it does exist [email protected] Excel Programming 4 June 18th 06 06:08 PM
Am I Looking For Something That Doesn't Exist? seanryann Excel Discussion (Misc queries) 11 April 1st 06 06:10 PM
Command Line. How to tell to XL : If the xls file exist : Open it, if it does not exist : Create it. Tintin92 Excel Programming 3 March 11th 06 06:45 PM


All times are GMT +1. The time now is 11:51 PM.

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"