worksheet

G

Guest

How would I code, if there is worksheet titled something,
select it. If there isn't a worksheet titled that,
create it? Thank you.
 
B

Bob Phillips

If Not IsSheet("mySheet") Then
Worksheets.Add.Name = "mySheet"
End If

Function IsWsSheet(sh As String, Optional wb As Workbook) As Boolean
Dim oWs As Worksheet

If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
Set oWs = wb.Worksheets(sh)
On Error GoTo 0
IsWsSheet = Not oWs Is Nothing

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
C

Chip Pearson

Try some code like the following:


Dim WS As Worksheet
On Error Resume Next
Set WS = Worksheets("TheSheetName")
If WS Is Nothing Then
Set WS = Worksheets.Add
WS.Name = "TheSheetName"
End If
WS.Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top