View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default How to check the Sheet name exist before running Macro code

Copy the below function and use that in code as below

Sub Macro()
'If sheet do not exist then exit procedure
If Not IsSheetExists("mySheet") Then Exit Sub

End Sub


Function IsSheetExists(strSheet As String) As Boolean
On Error Resume Next
Dim ws As Worksheet
Set ws = Sheets(strSheet)
If Not ws Is Nothing Then IsSheetExists = True
End Function

--
Jacob


"tlee" wrote:

Hello all,

Could anyone know how to check the sheet name (e.g. "mySheet") exist before
running the rest macro code ?

Thanks,

tlee


.