ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to detect a col/row deletion? (https://www.excelbanter.com/excel-programming/277079-how-detect-col-row-deletion.html)

Mauricio Villada

How to detect a col/row deletion?
 
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



Frank Isaacs

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






All times are GMT +1. The time now is 08:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com