ExcelBanter

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

Kaval

Worksheet exists
 
Is there an easy way to find out if a sheet with a particular name already
exists in a workbook?

Thanks, Kaval

JE McGimpsey

Worksheet exists
 
One way:

Const sNAME As String = "ParticularName"
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(sNAME)
On Error GoTo 0
If Not ws Is Nothing Then
MsgBox "Worksheet " & sNAME & " exists"
Else
MsgBox "Worksheet " & sNAME & " doesn't exist"
End If

In article ,
"Kaval" wrote:

Is there an easy way to find out if a sheet with a particular name already
exists in a workbook?

Thanks, Kaval


Stuart[_30_]

Worksheet exists
 
On Error Resume Next
Sheets("MySheet").Select
If Err Then
MsgBox "MySheet does not exist"
End If
On Error GoTo 0


"Kaval" wrote in message
...
Is there an easy way to find out if a sheet with a particular name already
exists in a workbook?

Thanks, Kaval





All times are GMT +1. The time now is 10:32 AM.

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