So I had this working but for some reason I updated the code and it does not compile. I have provided the code and what I am trying to accomplish in the comments as well
I am trying to do an if statement that will check a hidden worksheet via the userform
if contents are in the sheet, they will be removed before the form is closed
if contents are not found then there will be nothing to clear and they will see a different series of message boxes before closing
The if statement below does not properly search the worksheet "userfeedbackata" to see if it's empty and the clear data sub command also does not seem to be working but was working previously even though I have not changed the code in that specific command, only in the closecommand_click() function
Private Sub CloseCommand_Click()
Application.ScreenUpdating = False
'Worksheets("userfeedbackdata").Select
'want hidden worksheet (userfeedbackdata) to be checked for empty data
If WorksheetFunction.CountBlank = True Then
'check if worksheet has data, if so clear data
MsgBox "Sheet2 is blank.", vbOKOnly + vbInformation
MsgBox "Any information entered without selecting the capture feedback button will not be saved. Are you sure you want to close this form", vbYesNo, "Close Windows 10 Feedback Form?"
MsgBox "clearing data"
Clear_Data
'this funcion clears the data in the userfeedbackdata spreadsheet only
MsgBox "The Windows 10 Feedback Form Session will now close.", vbOKOnly, "Close Windows 10 User Feedback Form"
Exit Sub
Else
'if not then close the file because there is no data to clear
MsgBox "No Data To Clear"
If MsgBox("Any information entered without selecting the capture feedback button will not be saved. Are you sure you want to close this form", vbYesNo, "Close Windows 10 Feedback Form?") = vbNo Then
Exit Sub
Else
MsgBox "The Windows 10 Feedback Form Session will now close.", vbOKOnly, "Close Windows 10 User Feedback Form"
End If
End If
Unload frmWindows10Feedback
ThisWorkbook.Saved = True
ThisWorkbook.Close
End Sub
Private Sub Clear_Data()
Worksheets("userfeedbackdata").Rows("2:" & Rows.Count).ClearContents
End Sub
Display More