G
Guest
I have a spreadsheet which has some macros associated with it and need to
make sure that columns are not deleted or inserted. For the case where the
context menu is used to delete or insert a columns, the following code works
because one has to select the entire column:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Rows.Count = 65536 Then
ActiveSheet.Protect
Else
ActiveSheet.Unprotect
End If
End Sub
(The above code places the spreadsheet in the protection mode if an
entire
column is selected and unprotects it when a cell or range of cells is
selected.)
However, this does not work if someone decides to delete or insert using the
Excel menu. I don't want to keep the sheet in a protected mode since this is
too restrictive, but I do need a way to protect the columns. Any help with
this is appreciated.
make sure that columns are not deleted or inserted. For the case where the
context menu is used to delete or insert a columns, the following code works
because one has to select the entire column:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Rows.Count = 65536 Then
ActiveSheet.Protect
Else
ActiveSheet.Unprotect
End If
End Sub
(The above code places the spreadsheet in the protection mode if an
entire
column is selected and unprotects it when a cell or range of cells is
selected.)
However, this does not work if someone decides to delete or insert using the
Excel menu. I don't want to keep the sheet in a protected mode since this is
too restrictive, but I do need a way to protect the columns. Any help with
this is appreciated.