macro bordure en fonction de la cellule et de la valeur
Bonjour à tous,
Je suis débutant en programmation sur VBA, depuis quelques jours j'essaye de faire une macro mais là je bloque, est ce que quelqu'un pourrait m'aider svp ?
Voici mon problème :
Je veux créer une macro qui modifie les bordures automatiquement des case X si case Y est change de valeur. En gros si je modifie l'une des cases suivantes (BR18, BV18, BZ18, CD18) je veux qu'il sélectionne la case décalé de 0 ligne et 2 colonnes et qu'il modifie ses bordures en fonctions de la valeur de la case (BR18, BV18, BZ18, CD18)
Code:
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| Sub NV()
Dim Rng As Range
If Not Intersect(ActiveCell, Range("BR19")) Is Nothing Then
Set Rng = Range("BR18")
If Not Intersect(ActiveCell, Range("BV19")) Is Nothing Then
Set Rng = Range("BV18")
If Not Intersect(ActiveCell, Range("BZ19")) Is Nothing Then
Set Rng = Range("BZ18")
If Not Intersect(ActiveCell, Range("CD19")) Is Nothing Then
Set Rng = Range("CD18")
If Rng = 1 Then
Rng.Offset(0, 2).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlDash
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDash
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlDash
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End If
If Rng = 2 Then
Rng.Offset(0, 2).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDash
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
Selection.Borders (xlEdgeBottom)
.LineStyle = xlDash
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlMedium
End If
If Rng = 3 Then
Rng.Offset(0, 2).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDash
.ThemeColor = 1
.TintAndShade = -0.249946592608417
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThick
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End If
End If
End If
End If
End If
End Sub |
Je vous remercie par avance de votre aide.