Private Sub Worksheet_Change(ByVal Target As Range)
Dim TS As ListObject 'déclare la variable TS (Tableau Structuré)
Dim LR As Integer 'déclare la variable LR (Ligne de Référence)
If Target.Count > 1 Then Exit Sub 'si plusieurs cellules sélectionnées, sort de la procédure
If Target.ListObject Is Nothing Then Exit Sub 'si la cellule modifiée n'est pas dans un tableau structuré, sort de la procédure
Set TS = Target.ListObject 'définit le tableau structuré TS
Me.Unprotect "1234" 'déprotège l'onglet avec mot de passe = "1234"
'Si le changement a lieu ailleurs que...
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim oList As ListObject
Set oList = Target.ListObject
If Not oList Is Nothing And Target.Count = 1 Then
'------------------------------------------------------------------------
' Attention le numéro de ligne de la cible n'est pas celui du tableau !
'------------------------------------------------------------------------
lig = Target.Row - 4
If oList.Range(lig, 5) = "V" Then
MsgBox "Pas touche !!!", vbExclamation
End If
End If
Set oList = Nothing
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim TS As ListObject 'déclare la variable TS (Tableau Structuré)
Dim LR As Integer 'déclare la variable LR (Ligne de Référence)
If Target.Count > 1 Then Exit Sub 'si plusieurs cellules sélectionnées, sort de la procédure
If Target.ListObject Is Nothing Then Exit Sub 'si la cellule modifiée n'est pas dans un tableau structuré, sort de la procédure
Set TS = Target.ListObject 'définit le tableau structuré TS
Me.Unprotect "1234" 'déprotège l'onglet avec mot de passe = "1234"
'Si le changement a lieu ailleurs que dans la colonne "STATUT". sort de la procédure
If Application.Intersect(Target, TS.ListColumns("STATUT").Range) Is Nothing Then Exit Sub
Application.EnableEvents = False 'empêche les événementielles (pour éviter de boucler)
Target.Value = UCase(Target.Value) 'remplace v par V le cas échéant (relance l'événementielle)
Application.EnableEvents = True 'autorise les événementielles
LR = Target.Row - TS.HeaderRowRange.Row 'définit la ligne de référence LR
TS.ListRows(LR).Range.Locked = IIf(Target.Value = "V", True, False) 'vérouille la ligne de référence LR si "V"
Me.Protect "1234" 'protège l'onglet avec mot de passe "1234"
End Sub
Bonjour Pounet,Bonjour,
Comme ceci ?
Claude alias Pounet95
VB:Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim oList As ListObject Set oList = Target.ListObject If Not oList Is Nothing And Target.Count = 1 Then '------------------------------------------------------------------------ ' Attention le numéro de ligne de la cible n'est pas celui du tableau ! '------------------------------------------------------------------------ lig = Target.Row - 4 If oList.Range(lig, 5) = "V" Then MsgBox "Pas touche !!!", vbExclamation End If End If Set oList = Nothing End Sub
Rebonjour Pounet,Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim oList As ListObject Set oList = Target.ListObject If Not oList Is Nothing And Target.Count = 1 Then '------------------------------------------------------------------------ ' Attention le numéro de ligne de la cible n'est pas celui du tableau ! '------------------------------------------------------------------------ lig = Target.Row - 4 If oList.Range(lig, 5) = "V" Then MsgBox "Pas touche !!!", vbExclamation End If End If Set oList = Nothing End Sub