I'm writing code in a template and I want the user to basically get prompted when the data is already formatted in my template sheet. If it is present (ie the formatted sheet tab is there) the user will be prompted to delete all formatted tabs.
The code is as follows:
Dim wb As Workbook Dim sh As Worksheet Dim button As Integer Dim datapresent As Boolean For Each book In Workbooks datapresent = False For Each Sheet In book.Worksheets If Sheet.Name = "Sheet1" Or Sheet.Name = "Sheet2" Or Sheet.Name = "Sheet3" datapresent = True End If If datapresent = True Then button = MsgBox("Data already present. Do you want to delete and re-format?", vbQuestion + vbYesNo + vbDefaultButton2, "Continue?") End If Next Sheet Next book
The only issue is that I get the popup box three times. I only want it to pop up once for any of those instances. If it finds one of them, I have an option to delete all sheets that it finds.
Hope this makes sense.