- Mar 5, 2021
- Office Version
I run my code to duplicate a worksheet. If the worksheet is already existed , then no duplication of sheet and message box (Sheet (sheetname) does exists) will show. But this message box will also pop up when new sheet is created but I do not want this. I only want this msg box to pop up when I run the marco again and found the same sheetname already there. Please help.
Function DoesSheetExists(sh As String) As Boolean Dim ws As Worksheet On Error Resume Next Set ws = Sheets(sh) On Error GoTo 0 If Not ws Is Nothing Then DoesSheetExists = True End Function Sub Check() Dim szToday As String szToday = Format(Date, "d mmm yyyy") If DoesSheetExists(szToday) Then MsgBox "Sheet " & szToday & " does exists" Else Call Module18.BlankSheet03 MsgBox "Sheet" & szToday & " Created" End If End Sub