Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sum of specific cell from several worksheets | Excel Discussion (Misc queries) | |||
If any specific #s are present in range, show each in another cell | Excel Worksheet Functions | |||
Display characters present after a specific character | Excel Discussion (Misc queries) | |||
For Each wks In ActiveWorkbook.Worksheets bar a specific one? | Excel Discussion (Misc queries) | |||
SUM/COUNT column(s) based on specific value present within the column | Excel Worksheet Functions |