The work-sheet "celldel" code is as below. It disallows row 'insert' and 'delete' methods by using right click on the Row Number bar (left side) and then choosing either Insert or delete. The change that I want to do, is allow insert and disallow delete method.
Thanks and best regards
Vilas Desai
Option Explicit
Private WithEvents MouseRclickCelDel As CommandBarButton
Private WithEvents MouseRclickRowDel As CommandBarButton
Private WithEvents MouseRclickColDel As CommandBarButton
Private WithEvents MenuEditDel As CommandBarButton
Private WithEvents MouseRClickClearContents1 As CommandBarButton
Private WithEvents MouseRClickClearContents2 As CommandBarButton
Private WithEvents MouseRClickClearContents3 As CommandBarButton
Private Sub Class_Initialize()
Set MouseRclickCelDel = Application.CommandBars.FindControl(, 292) ' Mouse right click Cell delete
Set MouseRclickRowDel = Application.CommandBars.FindControl(, 293) 'Mouse right Full Row Delete
Set MouseRclickColDel = Application.CommandBars.FindControl(, 294) 'Mouse right Full Col Delete
Set MenuEditDel = Application.CommandBars.FindControl(, 478) 'Menu -> Edit -> delete
Set MouseRClickClearContents1 = Application.CommandBars.FindControl(, 780) 'Mouse right Clear Contents
Set MouseRClickClearContents2 = Application.CommandBars.FindControl(, 1523) 'Mouse right Clear Contents
Set MouseRClickClearContents3 = Application.CommandBars.FindControl(, 3125) 'Mouse right Clear Contents
End Sub
Private Sub MouseRclickCelDel_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
MsgBox "Deleting Cells are Disabled in " & Selection.Worksheet.Name & ".", vbInformation
Cancel = True
End If
End Sub
Private Sub MouseRclickRowDel_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
If (Selection.Rows.Count = 1) Then
If (Intersect(Selection, Range("D:D")).Count = 1) Then
If Intersect(Selection, Range("D:D")).Value = "" Then
Cancel = False
Else
Call Mesg
Cancel = True
End If
Else
Call Mesg
Cancel = True
End If
Else
Call Mesg
Cancel = True
End If
End If
End Sub
Private Sub MenuEditDel_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
MsgBox "Deleting Cells are Disabled in " & Selection.Worksheet.Name & ".", vbInformation
Cancel = True
End If
End Sub
Private Sub MouseRclickColDel_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
MsgBox "Deleting Entire Column is Disabled in " & Selection.Worksheet.Name & ".", vbInformation
Cancel = True
End If
End Sub
Private Sub Mesg()
MsgBox "Deleting Cells are Disabled in " & Selection.Worksheet.Name & _
"." & Chr(13) & Chr(10) & "If you want to Delete entire row first clear the contents in Cell ""D""," & _
Chr(13) & Chr(10) & "Then try Deleting the Entire Row." & _
Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Note: Multiple Entire Rows deletion are not allowed.", _
vbInformation, Selection.Worksheet.Name
End Sub
Private Sub MouseRClickClearContents1_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
MsgBox "Deleting Cells are Disabled in " & Selection.Worksheet.Name & ".", vbInformation
Cancel = True
End If
End Sub
Private Sub MouseRClickClearContents2_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
MsgBox "Deleting Cells are Disabled in " & Selection.Worksheet.Name & ".", vbInformation
Cancel = True
End If
End Sub
Private Sub MouseRClickClearContents3_Click(ByVal DelCel As Office.CommandBarButton, Cancel As Boolean)
If (Selection.Worksheet.CodeName = "MasterList") Then
MsgBox "Deleting Cells are Disabled in " & Selection.Worksheet.Name & ".", vbInformation
Cancel = True
End If
End Sub
Bookmarks