XL 2016 coloration automatique

halecs93

XLDnaute Impliqué
Bonjour,

Dans le fichier exemple que je joins, je cherche à colorer uniquement les cellules précédées et suivies immédiatement de cellules déjà colorées.

Bon, un "dessin" vaut souvent mieux qu'une explication bancale ;)

Donc le fichier est joint.

Un grand merci à tout le monde

1707750424949.png
 

Pièces jointes

  • coloration automatique - exceldownloads.xlsx
    10.7 KB · Affichages: 0
Solution
VB:
Sub Colore()
    For L = 2 To 1000 ' A adapter suivant besoin
        If Cells(L, "A").Interior.Color = vbWhite And _
            Cells(L, "A").Offset(-1, 0).Interior.Color <> vbWhite And _
            Cells(L, "A").Offset(1, 0).Interior.Color <> vbWhite Then
                Cells(L, "A").Interior.Color = vbYellow
                Cells(L, "A") = "TTT"
        End If
    Next L
End Sub

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonjour Halecs,
En PJ un essai avec cette macro :
VB:
Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Fin: If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("A1:A1000")) Is Nothing Then ' Plage à adapter
        If Target = "" Then Exit Sub
        Set Cell = Range(Target.Address)
        If Cell.Offset(-1, 0).Interior.Color <> vbWhite And _
            Cell.Offset(1, 0).Interior.Color <> vbWhite Then
                Cell.Interior.Color = vbYellow
        End If
    End If
Fin:
End Sub
La coloration éventuelle se fait quand on entre une valeur dans une cellule de la colonne A.
 

Pièces jointes

  • coloration automatique - exceldownloads.xlsm
    16.2 KB · Affichages: 0

halecs93

XLDnaute Impliqué
Bonjour Halecs,
En PJ un essai avec cette macro :
VB:
Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Fin: If Target.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("A1:A1000")) Is Nothing Then ' Plage à adapter
        If Target = "" Then Exit Sub
        Set Cell = Range(Target.Address)
        If Cell.Offset(-1, 0).Interior.Color <> vbWhite And _
            Cell.Offset(1, 0).Interior.Color <> vbWhite Then
                Cell.Interior.Color = vbYellow
        End If
    End If
Fin:
End Sub
La coloration éventuelle se fait quand on entre une valeur dans une cellule de la colonne A.
Tout d'abord merci.

Mais en effet, je souhaitais une macro (en module) que je puisse déclencher sans avoir à entrer une valeur dans la cellule pour la colorer. Simplement, une macro qui repère chaque cellule unique encadrées (en haut et en bas) par des cellules colorées. Et dans ce cas là, elle prend la couleur jaune.
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
Re,
Alors ceci peut être :
VB:
Sub Colore()
    For L = 2 To Range("A65500").End(xlUp).Row
        If Cells(L, "A") <> "" And _
            Cells(L, "A").Offset(-1, 0).Interior.Color <> vbWhite And _
            Cells(L, "A").Offset(1, 0).Interior.Color <> vbWhite Then
                Cells(L, "A").Interior.Color = vbYellow
        End If
    Next L
End Sub
 

Pièces jointes

  • coloration automatique - exceldownloads (V2).xlsm
    16.4 KB · Affichages: 0

halecs93

XLDnaute Impliqué
Re,
Alors ceci peut être :
VB:
Sub Colore()
    For L = 2 To Range("A65500").End(xlUp).Row
        If Cells(L, "A") <> "" And _
            Cells(L, "A").Offset(-1, 0).Interior.Color <> vbWhite And _
            Cells(L, "A").Offset(1, 0).Interior.Color <> vbWhite Then
                Cells(L, "A").Interior.Color = vbYellow
        End If
    Next L
End Sub
Ca s'en rapproche... mais en fait, je souhaitais que la cellule se colore et inscrive "ttt", mais pas que l'inscription "ttt" permette la colorisation.

En gros, déclencher la macro colore la cellule et y inscrit "ttt"
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
VB:
Sub Colore()
    For L = 2 To 1000 ' A adapter suivant besoin
        If Cells(L, "A").Interior.Color = vbWhite And _
            Cells(L, "A").Offset(-1, 0).Interior.Color <> vbWhite And _
            Cells(L, "A").Offset(1, 0).Interior.Color <> vbWhite Then
                Cells(L, "A").Interior.Color = vbYellow
                Cells(L, "A") = "TTT"
        End If
    Next L
End Sub
 

Pièces jointes

  • coloration automatique - exceldownloads (V4).xlsm
    16.8 KB · Affichages: 7
Dernière édition:

halecs93

XLDnaute Impliqué
VB:
Sub Colore()
    For L = 2 To 1000 ' A adapter suivant besoin
        If Cells(L, "A").Interior.Color = vbWhite And _
            Cells(L, "A").Offset(-1, 0).Interior.Color <> vbWhite And _
            Cells(L, "A").Offset(1, 0).Interior.Color <> vbWhite Then
                Cells(L, "A").Interior.Color = vbYellow
                Cells(L, "A") = "TTT"
        End If
    Next L
End Sub
Bonjour,

C'est tout à fait ce que je souhaitais.

Un grand grand merci.
 

Discussions similaires

Réponses
6
Affichages
324

Statistiques des forums

Discussions
312 211
Messages
2 086 289
Membres
103 170
dernier inscrit
HASSEN@45