Private Sub Worksheet_SelectionChange(ByVal Target As Range) '------------------------------------------------------------------------------ Dim n As Long Dim avviso As String n = ActiveCell.Row If n < 7 Then 'avviso = MsgBox("non puoi modificare questa cella!!!", vbOKOnly + vbCritical, "ATTENZIONE!") ActiveSheet.Protect Password:="987654" Exit Sub End If If Not Intersect(Target, Range("C:C, D:D, E:E, F:F, G:G, H:H, I:I")) Is Nothing Then 'ActiveSheet.Unprotect "987654" ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True _ , AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowFiltering:=True Else 'ActiveSheet.Unprotect "987654" ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True _ , AllowFormattingCells:=False, AllowInsertingHyperlinks:=False, AllowFiltering:=True End If End Sub
Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim n As Long Dim avviso As String n = ActiveCell.Row If n < 7 Then 'avviso = MsgBox("non puoi modificare questa cella!!!", vbOKOnly + vbCritical, "ATTENZIONE!") ActiveSheet.Protect Password:="987654" Exit Sub End If If Not Intersect(Target, Range("C:C, D:D, E:E, F:F, G:G, H:H, I:I")) Is Nothing Then 'ActiveSheet.Unprotect "987654" '--------------------------------------------------------- Select Case Target.Column Case Is = 3 ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowFiltering:=True MsgBox "Fatto con link" Case Else ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=False, AllowFiltering:=True MsgBox "Fatto senza link" End Select '--------------------------------------------------------- Else 'ActiveSheet.Unprotect "987654" ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=False, AllowInsertingHyperlinks:=False, AllowFiltering:=True MsgBox "Fatto Altro" End If End Sub
'--------------------------------------------------------- Select Case Target.Column Case Is = 3 ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowFiltering:=True 'MsgBox "Fatto con link" Case Is = 5 ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowFiltering:=True 'MsgBox "Fatto con link" Case Is = 7 ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=True, AllowFiltering:=True Case Else ActiveSheet.Protect Password:="987654", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True, AllowInsertingHyperlinks:=False, AllowFiltering:=True 'MsgBox "Fatto senza link" End Select '---------------------------------------------------------