Option Explicit
Public StartClear As Integer
Sub ClearDataBelowThisRow()
Dim Question As Integer
Dim Password, Msg, Answer, Confirm, MoreOptions As VbMsgBoxResult
On Error GoTo LastLine
Question = InputBox("What is the last row number you want to KEEP?", "Keep rows down to...")
If Question <= 0 Then Exit Sub
StartClear = Question + 1
ActiveSheet.Rows(StartClear & ":65536").Select
Answer = MsgBox("Clear all entries from row " & StartClear & " down?", vbYesNo, "Cleaning out " & 65536 - StartClear & " Rows")
If Answer = vbNo Then
Range("A" & StartClear).Select
Exit Sub
End If
Password = Application.InputBox(prompt:="Please enter password to confirm your" & _
"authority to take this action...", Title:="A Password Is Required For This Action...")
If Password <> "123" Then WrongPassword Else
ActiveSheet.Unprotect
Confirm = MsgBox("Click YES to clear the selected region - (Leave the cell formulae," & vbLf & _
"cell formatting, conditional formatting and data validation intact)" & vbLf & _
"" & vbLf & _
"Click NO for other choices...", vbYesNoCancel, "Confirm Details...")
Application.ScreenUpdating = False
If Confirm = vbYes Then
On Error Resume Next
Selection.SpecialCells(xlCellTypeConstants, 23).ClearContents
Range("A" & StartClear).Select
Exit Sub
End If
If Confirm = vbNo Then
MoreOptions = MsgBox("Click YES to clear the contents AND the formulae from the selected region." & vbLf & _
"(Leave the cell formatting, conditional formatting and data validation intact)" & vbLf & _
"" & vbLf & _
"Click NO to Delete absolutely everything...", vbYesNoCancel, "CHOOSE CAREFULLY !")
If MoreOptions = vbYes Then
On Error Resume Next
Selection.ClearContents
Range("A" & StartClear).Select
Exit Sub
End If
If MoreOptions = vbNo Then
On Error Resume Next
Selection.Delete
Range("A" & StartClear).Select
Exit Sub
End If
If MoreOptions = vbCancel Then
Range("A" & StartClear).Select
Exit Sub
End If
If Confirm = vbCancel Then
Range("A" & StartClear).Select
Exit Sub
End If
Exit Sub
End If
LastLine:
End Sub
Private Sub WrongPassword()
Dim Msg As VbMsgBoxResult
Range("A" & StartClear).Select
Msg = MsgBox("Denied : - That is not the password !", vbExclamation, "Incorrect Password")
End
End Sub
|