Colorer aléatoirement sous condition

Bonjour tt le monde,

Je cherche un code vba qui sert à colorer chaque sélection de ligne avec le même Id avec une couleur aléatoire.

et merci.

Voilà une piste, ça colore aléatoirement les cellules sélectionnées.

Sub melch()
Randomize
For Each cell In Selection
    a = Round(255 * Rnd())
    b = Round(255 * Rnd())
    c = Round(255 * Rnd())
    cell.Interior.Color = RGB(a, b, c)
Next
End Sub

Après pour adapter à ton fichier, il faut nous joindre un exemple.

Bonjour achraf2020, le fil,

Un essai.......

Source: ..............http://boisgontierjacques.free.fr/pages_site/Doublons.htm

Sub GroupColor()
  couleurs = Array(1, 3, 4, 6, 7, 8, 14, 15, 17, 20, 22, 24, 26, 27, 28, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 50, 53)
  Set mondico = CreateObject("Scripting.Dictionary")
  For Each c In Range("a2", [a65000].End(xlUp))
    If c <> "" Then mondico.Item(c.Value) = mondico.Item(c.Value) + 1
  Next c
  For Each c In Range("a2", [a65000].End(xlUp))
   If c <> "" Then
     nocoul = (Application.Match(c.Value, mondico.keys, 0)) Mod UBound(couleurs)
     If mondico.Item(c.Value) > 1 Then c.Interior.ColorIndex = couleurs(nocoul)
     If mondico.Item(c.Value) <> "" Then c.Interior.ColorIndex = couleurs(nocoul)
   End If
  Next c
End Sub

Cordialement,

Rechercher des sujets similaires à "colorer aleatoirement condition"