Good morning all. I have an issue that is driving me crazy and have spent way too long trying to search / debug a solution. Please bear with me as this is my first post here.
Essentially, I have a userform that I activate within my spreadsheet for a few parameters for filtering of data. Once the OK is selected, I delete a couple of sheets and re-create them from scratch. This all works just fine for the most part, except that deleting one particular sheet causes the userform to fully reset back to scratch. I normally hide the userform prior to running the function that calls the delete, then when I display it again, everything is reset. If I dont hide it, then the delete function closes it down anyhow (I assume the userform is being fully unloaded from memory).
The same function deletes both sheets, yet only one sheet seems to cause the userform to reset. Whether its modal or not has made no difference.
Any help would be appreciated. I have posted the function that I call to delete / replace the sheet below. Even if I dont call this, and just slot an inline sheet.delete in place, I get the same result.
note:
1. The userform isnt necessarily called from the sheet being deleted
2. The sheet that causes problems does have VBA code attached to it, but even if I delete the code, it didnt help.
Essentially, I have a userform that I activate within my spreadsheet for a few parameters for filtering of data. Once the OK is selected, I delete a couple of sheets and re-create them from scratch. This all works just fine for the most part, except that deleting one particular sheet causes the userform to fully reset back to scratch. I normally hide the userform prior to running the function that calls the delete, then when I display it again, everything is reset. If I dont hide it, then the delete function closes it down anyhow (I assume the userform is being fully unloaded from memory).
The same function deletes both sheets, yet only one sheet seems to cause the userform to reset. Whether its modal or not has made no difference.
Any help would be appreciated. I have posted the function that I call to delete / replace the sheet below. Even if I dont call this, and just slot an inline sheet.delete in place, I get the same result.
note:
1. The userform isnt necessarily called from the sheet being deleted
2. The sheet that causes problems does have VBA code attached to it, but even if I delete the code, it didnt help.
Code:
Sub DuplicateTemplate(TemplateName As String, NewSheetName As String)
' ********************** Unhide template sheet, duplicate it, rename it and re-hide the template ************************
Dim NewDataSheet As Worksheet
' *** Remove any duplicate sheet copy
Application.DisplayAlerts = False
On Error GoTo errCopyBlankTemplate
Sheets(NewSheetName).Delete
errCopyBlankTemplate:
On Error GoTo 0
Application.DisplayAlerts = True
' *** Unhide template and copy / rename
ThisWorkbook.Worksheets(TemplateName).Visible = True
ThisWorkbook.Worksheets(TemplateName).Copy _
after:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
Set DataSheet = ActiveSheet
DataSheet.Name = NewSheetName
ThisWorkbook.Worksheets(TemplateName).Visible = False
End Sub