View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Isaacs Frank Isaacs is offline
external usenet poster
 
Posts: 30
Default How to detect a col/row deletion?

I would recommend against this course of action, going instead for the cell
protection feature which is available. You can lock cells and then protect
the worksheet so the locked cells can't be deleted. You can optionally
specify a password as well.

If, however, you require the functionality you requested, this code is a
STARTING point; tested in Excel XP. It will NOT work in XL97, and I didn't
test it in XL 2000:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Static bUndoing As Boolean

If Target.Address = "$C:$C" Then
If Not bUndoing Then
bUndoing = True
Application.Undo
Else
bUndoing = False
End If
End If
End Sub

Instead of the very simple target.address line above, you'll have to check
to see if the target is within any set of cells you choose. Check out the
Intersect vba method for ideas of how to do that.

Please note - there are numerous ways things can be selected and deleted.
For example, if the user has a multiple selection range and deletes, you'd
have to test each range in the multiple selection to see if it falls in your
desired protection area. (Try adding this code at the beginning of the code
above for debugging purposes: Application.StatusBar = Target.Address).

I think, therefore, that this is going to be a difficult thing to do; I'd
strongly recommend going with protection instead.
--
HTH -

-Frank
Microsoft Excel MVP
Dolphin Technology Corp.
http://vbapro.com




"Mauricio Villada" wrote in message
...
I want to detect this event in order to avoid the deletion of some

critical
columns.

Any ideas on what event would fire?

Thanks,
MV