Delete Line Macro - IF Function
Assuming your named range is called "ProtectedRange" I would do it like this:
varAnswer = MsgBox("Delete Line?", vbOKCancel, "Please Confirm")
If ((varAnswer = 1) and
Application.Intersect(Range("ProtectedRange"),Sele ction) Is Nothing) Then ...
The Intersect method sees if there is any "overlap" between the selected
range and the range you want to protect from deletion - if none, then do the
delete...
HTH
"PW11111" wrote:
Hi,
I'm trying to create a macro that deletes a line from a spreadsheet i am
developing. The code is below, its works fine but I would like to specify
rows that the macro will not delete.
I need to know the code that specifies either - to end the macro if a
specific row is chosen for deletion. Or even better would be the code that
specifies that the macro will only delete a line within a specific named
range.
Application.ScreenUpdating = False
ActiveSheet.Unprotect "gpro"
varAnswer = MsgBox("Delete Line?", vbOKCancel, "Please Confirm")
If varAnswer = 1 Then
If Range("D17") = "2" Then
ActiveCell.EntireRow.Select
Selection.Delete Shift:=xlUp
Rows("180:180").Select
Selection.EntireRow.Hidden = True
Range("E13").Select
Else
End If
Else: End
End If
ActiveSheet.Protect "gpro", DrawingObjects:=True, Contents:=True,
Scenarios:=True
End help would be great.
Phil
|