I have the below simple vba code assigned to a button on my workbook, it’s to create a copy of the active sheet on a monthly basis, but I also have the workbook structure disabled and protected after the code is run. What I need assistance with is, adding code to the existing code preventing it from creating duplicates if the button is clicked in error more than once.
Sub CopyMyWorkSheet() ThisWorkbook.Unprotected “Password” On Error GoTo Err_MyWorkSheet Dim ws As Worksheet Set ws = ActiveSheet Dim wsc As Worksheet ws.Copy , ws Set wsc = ThisWorkbook.Worksheets(ws.Index + 1) wsc.Name = “MyWorkSheet “ & Format(DateAdd(“m”, 1, ws.[E3].Value), “mm-did-yy”) ThisWorkbook.Protect”Password” Exit_MyWorkSheet: Exit Sub Err_MyWorkSheet: MsgBox “Error “ & Err.Number & “: “ & Err.Description ThisWorkbook.Protect”Password” Resume Exit_MyWorkSheet End Sub
Thanks in advance…