Beug sur code VBA

Bonjour

Pouvez vous me dire ou est mon erreur sur ce code Beug sur la ligne If

Je vous remercie

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Worksheets("Feuil1").Select
Range("B9").Select
If Range("B9") = ("Machine 1") And Target(("C15:C19"), ("C21:C23" > 0)) Then MsgBox ("Saisie dans cette cellule Formellement interdite")
End Sub

Bonjour à tous !

Joco7915 comme ceci peut-être

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C15:C23")) Is Nothing Then
If Range("B9") = "Machine 1" And Target.Value > 0 Then
MsgBox ("Saisie dans cette cellule Formellement interdite")
Target.Value = ""
End If
End If
End Sub

Si vous entrez Machine X rien ne va se passer si vous saisissez une valeur dans la plage (C15:C23)

Bonne journée

Bonjour Nordick_Nation

Merci pour ton aide

En aménageant ton code comme suit j'ai le résultat souhaité dans un premier temps

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C15:C19,C21:C23")) Is Nothing Then
If Range("B9") = "Piece1" And Target.Value > 0 Then
MsgBox ("Saisie dans cette cellule Formellement interdite")
Target.Value = ""
End If
End If
End Sub

Comment je peux faire pour ajouter ceci en respectant les plages

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C13:C14,C17:C18,C20,C22:C23")) Is Nothing Then
If Range("B9") = "Piece2" And Target.Value > 0 Then
MsgBox ("Saisie dans cette cellule Formellement interdite")
Target.Value = ""
End If
End If
End Sub

Il faut que cela fonctionne selon le choix en B9

Je te remercie

Cordialement

Bonjour à tous!

Joco7915, un essai comme ceci mais pas testé entièrement placer les 2 codes dans la feuille et non dans un module standard

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C15:C19,C21:C23")) Is Nothing Then
If Range("B9") = "Piece1" And Target.Value > 0 Then
MsgBox ("Saisie dans cette cellule Formellement interdite")
Target.Value = ""
End If
End If
If Range("B9") <> "Piece1" Then
Call test
End If
End Sub

Private Sub test()
If Range("C14") Or Range("c15") Or Range("c17") Or Range("c18") Or Range("c20") Or Range("c22") Or Range("c23") > 0 Then
MsgBox ("Saisie dans cette cellule Formellement interdite")
Range("C14,C15,C17,C18,C20,C22,C23") = ""
End If
End Sub

Bonne journée !

Merci pour ton aide

Rechercher des sujets similaires à "beug code vba"