Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50123

Vba to allow user to insert rows/columns but not delete on unprotected sheet

$
0
0
I need to write some vba to allow users to insert new rows/columns but not allow them to delete them. I cannot protect the workbook as all users have the rights to unprotect the workbook.
I found the code below which works great for not allowing users to delete but does not allow inserting rows/columns either. Can anyone help.

Code:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
   
    If ((Target.Address = Target.EntireRow.Address Or _
    Target.Address = Target.EntireColumn.Address)) Then
       
       
        With Application
            .EnableEvents = False
            .Undo
            MsgBox "No deleting rows or columns", 16
            .EnableEvents = True
        End With
       
    Else
       
        Exit Sub
       
    End If
   
End Sub


Viewing all articles
Browse latest Browse all 50123

Trending Articles