Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim shp As Shape
Dim i As Integer
Dim cellValue As Double
Dim lowerLimit As Variant
Dim upperLimit As Variant
Set ws = ThisWorkbook.Sheets("Feuil1")
lowerLimit = ws.Range("E6").Value
upperLimit = ws.Range("H6").Value
' Vérifie si la modification a eu lieu dans une cellule d'intérêt
If Intersect(Target, Union(ws.Range("A18:A26"), ws.Range("B18:B26"), ws.Range("E6"), ws.Range("H6"))) Is Nothing Then Exit Sub
'Si E6 et H6 vides
If IsEmpty(lowerLimit) Or IsEmpty(upperLimit) Then
'Parcourt tous les shapes et les masque
For i = 1 To 18
Set shp = ws.Shapes("Rectangle " & i)
shp.Visible = msoFalse
Next i
Else
'Sinon parcourt tous les shapes
For i = 1 To 9
Set shp = ws.Shapes("Rectangle " & i)
cellValue = ws.Range("A" & i + 17).Value
'et compare valeur en A avec E6 et H6
If cellValue < lowerLimit Or cellValue > upperLimit Then
shp.Visible = msoFalse
Else
shp.Visible = msoTrue
End If
Next i
For i = 10 To 18
Set shp = ws.Shapes("Rectangle " & i)
cellValue = ws.Range("B" & i + 8).Value
'et compare valeur en B avec E6 et H6
If cellValue < lowerLimit Or cellValue > upperLimit Then
shp.Visible = msoFalse
Else
shp.Visible = msoTrue
End If
Next i
End If
End Sub