I currently have code to add a item to the right click menu to allow a user to delete a row in a password protected sheet, as the Delete option is grayed out.
I would like to amend this code to only allow the deletion of the selected row/rows if column C in the selected rows does not contain a value. If column c does contain a value, a message should appear to let the user know that row can not be deleted. Current code is listed below. Any Help would be greatly appretiated.
Thanks
Public Sub deleteRow()
Application.EnableCancelKey = xlDisabled
Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Sheets("LookAhead Schedule")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "Function Only Works in LookAhead Sheet!!!"
Else
If ws.Name = ActiveWorkbook.ActiveSheet.Name Then
ActiveSheet.Unprotect "password"
On Error Resume Next
ActiveSheet.ShowAllData
Selection.EntireRow.Delete
ActiveSheet.Protect _
Password:="password", _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
AllowFiltering:=True
Else
MsgBox "Function Only Works in LookAhead Sheet!!!"
End If
End If
Application.EnableCancelKey = xlInterrupt
End Sub
I would like to amend this code to only allow the deletion of the selected row/rows if column C in the selected rows does not contain a value. If column c does contain a value, a message should appear to let the user know that row can not be deleted. Current code is listed below. Any Help would be greatly appretiated.
Thanks
Public Sub deleteRow()
Application.EnableCancelKey = xlDisabled
Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Sheets("LookAhead Schedule")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "Function Only Works in LookAhead Sheet!!!"
Else
If ws.Name = ActiveWorkbook.ActiveSheet.Name Then
ActiveSheet.Unprotect "password"
On Error Resume Next
ActiveSheet.ShowAllData
Selection.EntireRow.Delete
ActiveSheet.Protect _
Password:="password", _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
AllowFiltering:=True
Else
MsgBox "Function Only Works in LookAhead Sheet!!!"
End If
End If
Application.EnableCancelKey = xlInterrupt
End Sub