ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   worksheet (https://www.excelbanter.com/excel-programming/298988-worksheet.html)

No Name

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

Bob Phillips[_6_]

worksheet
 

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)

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




Chip Pearson

worksheet
 
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




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





All times are GMT +1. The time now is 09:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com