1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| Dim PosLigne As Range
Dim Image As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
If Target.Count > 1 Then
With Application
.Undo
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
Exit Sub
End If
If Target.Column = 3 Then 'Colonne Symbole
Set PosLigne = Target.Offset(0, -2)
SupprimerImage
If Target <> "" Then 'Si le symbole inséré est non vide
Dim CompareSymbole As Range
Set CompareSymbole = Worksheets("API").Range("C:C").Find(Target, lookat:=xlWhole) 'Retrouve le Symbole dans la table API
If Not CompareSymbole Is Nothing Then 'Si on retrouve le Symbole
PosLigne.Value = CompareSymbole.Offset(0, 2)
Set Image = ActiveSheet.Pictures.Insert(PosLigne.Value)
With Image
.ShapeRange.LockAspectRatio = msoFalse
.Width = PosLigne.Width - 10
.Height = PosLigne.Height - 3
.Top = Rows(PosLigne.Row).Top + 2
.Left = Columns(PosLigne.Column).Left + 5
.Placement = xlMoveAndSize
.Locked = True
End With
PosLigne.Value = ""
Else: PosLigne.Value = 0 'Si le symbole est introuvable, alors on met 0 en valeur pour l'image de mise en forme conditionnelle
End If
Else: PosLigne.ClearContents 'Si le symbole inséré est vide, alors on efface l'image et l'url
End If
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub
Sub SupprimerImage()
For Each Image In ActiveSheet.Shapes
If Image.TopLeftCell.Address = PosLigne.Address Then
Image.Delete
Exit Sub
End If
Next Image
End Sub |
Partager