worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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)
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top