Help again: I'm trying to allow a user to decide not to delete a row in a protected table (part of a macro) if they click Cancel in a msgbox that pops up. I was able get the msgbox to pop up when the RemoveRows sub is run, but can't make it exit the RemoveRows sub if the user clicks Cancel.
Here is a private sub with msg, and the sub to delete:
Private Sub cmdMessageBoxDelete_Click()
MsgBox "Are you sure you want to delete the bottom row?" & _
vbCrLf & "You can't undo after clicking OK. ", _
VbMsgBoxStyle.vbOKCancel
End Sub
Sub RemoveRows()
Dim oLst As ListObject
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="myPW"
If ActiveSheet.ListObjects.Count > 0 Then
For Each oLst In ActiveSheet.ListObjects
If oLst.ListRows.Count > 1 Then
' Give user a way out of deleting row
Call cmdMessageBoxDelete_Click ' From private sub in this module
oLst.ListRows(oLst.ListRows.Count).Delete
End If
Next oLst
End If
ActiveSheet.Protect AllowSorting:=True, Password:="myPW"
End Sub
Help appreciated.
Thanks
-Alisser
Here is a private sub with msg, and the sub to delete:
Private Sub cmdMessageBoxDelete_Click()
MsgBox "Are you sure you want to delete the bottom row?" & _
vbCrLf & "You can't undo after clicking OK. ", _
VbMsgBoxStyle.vbOKCancel
End Sub
Sub RemoveRows()
Dim oLst As ListObject
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="myPW"
If ActiveSheet.ListObjects.Count > 0 Then
For Each oLst In ActiveSheet.ListObjects
If oLst.ListRows.Count > 1 Then
' Give user a way out of deleting row
Call cmdMessageBoxDelete_Click ' From private sub in this module
oLst.ListRows(oLst.ListRows.Count).Delete
End If
Next oLst
End If
ActiveSheet.Protect AllowSorting:=True, Password:="myPW"
End Sub
Help appreciated.
Thanks
-Alisser