Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default How to verify specific Worksheets are present

Windows 2k Pro
Excel 2000

I have a Workbook on which I need to do a relatively simple check using VBA
code. I want to scan the Workbook for four specific Worksheets (for example
the worksheets are named "Red", "Blue", "Green" and "Purple"). If any of
these are missing then I'd like to create a new Worksheet with the missing
name(s), AND I'd like to delete any Worksheets that are NOT named with one
of the four mentioned names.

I'm pretty sure I could do this, but I'm afraid my method would not be very
efficient at all. How many steps could this be done in? Or, what is the
most efficient way to do this?

TIA!

-gk-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default How to verify specific Worksheets are present

Sub addsheets()
Dim item As Variant
For Each item In _
Array("red", "green", "blue", "purple")
Add_Sheet CStr(item)
Next

End Sub
Private Sub Add_Sheet(sName As String)
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(sName)
If Err.Number < 0 Then
Err.Clear
Set ws = Worksheets.Add
ws.Name = sName
End If
Set ws = Nothing
On Error GoTo 0
End Sub


The Add_Sheet procedure sets the error trap then tries to
assign a specific sheet to the variable WS. If it fails,
the sheet doesn't exist , so the proc adds it and names
it.

Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Windows 2k Pro
Excel 2000

I have a Workbook on which I need to do a relatively

simple check using VBA
code. I want to scan the Workbook for four specific

Worksheets (for example
the worksheets are named "Red", "Blue", "Green"

and "Purple"). If any of
these are missing then I'd like to create a new

Worksheet with the missing
name(s), AND I'd like to delete any Worksheets that are

NOT named with one
of the four mentioned names.

I'm pretty sure I could do this, but I'm afraid my

method would not be very
efficient at all. How many steps could this be done

in? Or, what is the
most efficient way to do this?

TIA!

-gk-


.

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
Sum of specific cell from several worksheets richzip Excel Discussion (Misc queries) 2 December 11th 09 10:19 PM
If any specific #s are present in range, show each in another cell Steve Excel Worksheet Functions 6 June 24th 09 02:57 PM
Display characters present after a specific character [email protected] Excel Discussion (Misc queries) 3 December 11th 06 03:08 AM
For Each wks In ActiveWorkbook.Worksheets bar a specific one? Pank Mehta Excel Discussion (Misc queries) 4 March 30th 05 04:53 PM
SUM/COUNT column(s) based on specific value present within the column markx Excel Worksheet Functions 6 March 22nd 05 10:23 AM


All times are GMT +1. The time now is 02:16 AM.

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"