L
lili4905
Guest
Bonjour,
Ma feuille Excel contient la colonne O de type :
O
1 Région
2 Proxi
3 Nord
4 PACA
5 Nord
6 …
Le nb de ligne n’est jamais identique.
Grâce à un bouton relié à une macro, j’aimerais indiquer :
- la cellule Proxi en fond beige,
- la cellule « Est » en fond bleu écriture blanche,
- la cellule Nord en fond rouge…
J’hésite entre plusieurs instructions : for next, for each, do loop, ou if end if…
Je vous envoie 2 de mes essais qui ne fonctionnent malheureusement pas…
Sub Couleur()
Dim zone As Range 'Zone qui contient la base de données
Set zone = Range("O2").CurrentRegion
Dim Nom As String
If ActiveCell.FormulaR1C1 = "Proxi" Then
Selection.Interior.ColorIndex = 40
ElseIf ActiveCell.FormulaR1C1 = "Est" Then
Selection.Font.ColorIndex = 2
Selection.Interior.ColorIndex = 5
ElseIf ActiveCell.FormulaR1C1 = "Nord" Then
Selection.Interior.ColorIndex = 3
ElseIf ActiveCell.FormulaR1C1 = "PACA" Then
Selection.Interior.ColorIndex = 7
Else: Selection.Font.ColorIndex = 3
End If
End Sub
Sub CouleurBis()
Dim zone As Range 'Zone qui contient la base de données
Set zone = Range("O2").CurrentRegion
Dim CNom As Integer 'compteur de données
Dim F1 As Worksheet '1er onglet
Set F1 = Worksheets(1)
NbL = zone.Rows.Count
For CNom = 1 To NbL
If F1.Cells(CNom, 2).FormulaR1C1 = "Proxi" Then
ActiveCell.Interior.ColorIndex = 40
ElseIf ActiveCell.FormulaR1C1 = "Est" Then
ActiveCell.Font.ColorIndex = 2
ActiveCell.Interior.ColorIndex = 5
ElseIf ActiveCell.FormulaR1C1 = "Nord" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.FormulaR1C1 = "PACA" Then
ActiveCell.Interior.ColorIndex = 7
Else: ActiveCell.Font.ColorIndex = 3
End If
Next CNom
End Sub
Merci de votre aide.
Ma feuille Excel contient la colonne O de type :
O
1 Région
2 Proxi
3 Nord
4 PACA
5 Nord
6 …
Le nb de ligne n’est jamais identique.
Grâce à un bouton relié à une macro, j’aimerais indiquer :
- la cellule Proxi en fond beige,
- la cellule « Est » en fond bleu écriture blanche,
- la cellule Nord en fond rouge…
J’hésite entre plusieurs instructions : for next, for each, do loop, ou if end if…
Je vous envoie 2 de mes essais qui ne fonctionnent malheureusement pas…
Sub Couleur()
Dim zone As Range 'Zone qui contient la base de données
Set zone = Range("O2").CurrentRegion
Dim Nom As String
If ActiveCell.FormulaR1C1 = "Proxi" Then
Selection.Interior.ColorIndex = 40
ElseIf ActiveCell.FormulaR1C1 = "Est" Then
Selection.Font.ColorIndex = 2
Selection.Interior.ColorIndex = 5
ElseIf ActiveCell.FormulaR1C1 = "Nord" Then
Selection.Interior.ColorIndex = 3
ElseIf ActiveCell.FormulaR1C1 = "PACA" Then
Selection.Interior.ColorIndex = 7
Else: Selection.Font.ColorIndex = 3
End If
End Sub
Sub CouleurBis()
Dim zone As Range 'Zone qui contient la base de données
Set zone = Range("O2").CurrentRegion
Dim CNom As Integer 'compteur de données
Dim F1 As Worksheet '1er onglet
Set F1 = Worksheets(1)
NbL = zone.Rows.Count
For CNom = 1 To NbL
If F1.Cells(CNom, 2).FormulaR1C1 = "Proxi" Then
ActiveCell.Interior.ColorIndex = 40
ElseIf ActiveCell.FormulaR1C1 = "Est" Then
ActiveCell.Font.ColorIndex = 2
ActiveCell.Interior.ColorIndex = 5
ElseIf ActiveCell.FormulaR1C1 = "Nord" Then
ActiveCell.Interior.ColorIndex = 3
ElseIf ActiveCell.FormulaR1C1 = "PACA" Then
ActiveCell.Interior.ColorIndex = 7
Else: ActiveCell.Font.ColorIndex = 3
End If
Next CNom
End Sub
Merci de votre aide.