Bordure d'une Cellule en fonction de la couleur d'une autre cellule

Hello

J'ai un petit souci avec la macro suivante :

Je souhaite pour toutes les cellule rouges en plage 1 :

  • Mettre une bordure verte pour toutes les cellules "Non Rouge" en plage 2
  • Ne rien faire pour toutes les cellules "Rouge" en plage 2
Sub CHECKC1()

For i = 1 To 13
    For j = 1 To 13

    If Cells(i, j).Font.Color = RGB(242, 46, 0) <> Cells(i - 13, j).Font.Color = RGB(242, 46, 0) Then

        Select Case Cells(i, j).Interior.Color

            Case Is = RGB(242, 46, 0)
            Cells(i + 13, j).Borders.Weight = xlThick
            Cells(i + 13, j).Borders.LineStyle = xlGray75
            Cells(i + 13, j).Borders.Color = RGB(0, 255, 0)

        End Select

    Next j
Next i

End If

Range("F8:R20").BorderAround Weight:=xlThick

End Sub
12cellule-rouge.xlsm (17.93 Ko)

Bonjour,

Une proposition.

Cdlt.

Public Sub CHECK1()
Dim rng As Range, rng2 As Range, i As Long
Const R = 12018, G = 65280

    Application.ScreenUpdating = False

    Set rng = Range("plage_1")
    Set rng2 = Range("plage_2")

    For i = 1 To rng.Count
        If rng(i).Interior.Color = R Then
            If rng2(i).Interior.Color <> R Then
                With rng2(i)
                    .Interior.Color = G
                    With .Borders
                        .Weight = xlThick
                        .LineStyle = xlGray75
                    End With
                End With
            End If
        End If
    Next i

End Sub
13cellule-rouge.xlsm (27.88 Ko)

Hello

Cela répond parfaitement à ma demande.

Petit question : j'ai l'habitude de travailler avec les référence couleur RGB

Comment je retrouve les codes couleurs R = 12018, G = 65280 pour une autre autre ? C'est quoi ce type de référence ? je ne la connais pas

Bonjour,

Pour déclarer une constante j'avais besoin du nombre en long (entier).

Pour avoir ce nombre, en VBA :

Msgbox ActiveCell.Interior.Color

parfait merci

Hello,

Je souhaite utiliser la même macro mais avec 2 couleurs en condition ? Rouge (255,113,113) et Vert (146,208,80)

Règle de la Macro identique à la précédente mais avec ces deux couleurs :

Si sur la plage de cellule 1 les cellules sont coloré en Rouge (255,113,113) et Vert (146,208,80) et que les cellules correspondantes en plage 2 ne sont pas Rouge (255,113,113) ou Vert (146,208,80), alors colorié les cellules en plage 2 en Vert (G = 65280)

Public Sub CHECK1()
Dim rng As Range, rng2 As Range, i As Long
Const R = 12018, G = 65280

    Application.ScreenUpdating = False

    Set rng = Range("plage_1")
    Set rng2 = Range("plage_2")

    For i = 1 To rng.Count
        If rng(i).Interior.Color = R Then
            If rng2(i).Interior.Color <> R Then
                With rng2(i)
                    .Interior.Color = G
                    With .Borders
                        .Weight = xlThick
                        .LineStyle = xlGray75
                    End With
                End With
            End If
        End If
    Next i

End Sub
10macro-rouge-3.xlsm (28.38 Ko)

Je viens d'essayer ca mais ca ne fonctionne pas :)

Sub MR()
Dim rng As Range, rng2 As Range, i As Long
Const R = 7434751, V = 5296274, G = 65280

    Application.ScreenUpdating = False

    Set rng = Range("plage_1")
    Set rng2 = Range("plage_2")

    For i = 1 To rng.Count
        If rng(i).Interior.Color = R Then
            If rng2(i).Interior.Color <> R Then
                With rng2(i)
                    .Interior.Color = G
                    With .Borders
                        .Weight = xlThick
                        .LineStyle = xlGray75
                    End With
                End With
            End If
        End If

Else
            If rng(i).Interior.Color = V Then
       If rng2(i).Interior.Color <> V Then
                With rng2(i)
                    .Interior.Color = G
                    With .Borders
                        .Weight = xlThick
                        .LineStyle = xlGray75
                    End With
                End With
            End If
        End If

    Next i

End Sub

Bonjour,

A tester !

Public Sub CHECK1()
Dim rng As Range, rng2 As Range, i As Long
Const R = 12018, G = 65280

    Application.ScreenUpdating = False

    Set rng = Range("plage_1")
    Set rng2 = Range("plage_2")

    For i = 1 To rng.Count
        If rng(i).Interior.Color = R Or rng(i).Interior.Color = G Then
            If rng2(i).Interior.Color <> R Or rng2(i).Interior.Color <> G Then
                With rng2(i)
                    .Interior.Color = G
                    With .Borders
                        .Weight = xlThick
                        .LineStyle = xlGray75
                    End With
                End With
            End If
        End If
    Next i

End Sub

parfait merci beaucoup pour ton aide

Rechercher des sujets similaires à "bordure fonction couleur"