XL 2019 mettre en rouge

bennp

XLDnaute Occasionnel
Bonjour,

j'ai effectué une macro mais je souhaiterais l'optimiser et la réduire mais je ne trouve pas comment, pouvez vous m'aider svp ?

VB:
Sub ROUGE()
Dim i, j, k As Integer
Dim x As Variant
i = 127
Do
    i = i + 1
Loop Until Feuil1.Range("B" & i).Text = "GÉNÉRATEURS"
k = 4
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud"",RC[-11],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=5).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=5).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents

k = 10
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
k = 11
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
 k = 4
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""chaud"",RC[-11],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=5).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=5).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents

k = 10
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""chaud"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
k = 11
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""chaud"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=5).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 '''
  Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""chaud seul"",RC[-11],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents

k = 10
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""chaud seul"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
k = 11
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""chaud seul"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
 k = 4
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud seul"",RC[-11],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents

k = 10
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud seul"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
k = 11
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud seul"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
 k = 4
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud Seul"",RC[-11],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "Q").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents

k = 10
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud Seul"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
 
k = 11
 Feuil1.Range("AB" & i + k).FormulaR1C1 = "=IFERROR(FIND(""Chaud Seul"",RC[-19],1),"""")"
 x = Feuil1.Range("AB" & i + k).Value
    If Feuil1.Range("AB" & i + k) <> "" Then
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.FontStyle = "Gras"
       Feuil1.Cells(i + k, "I").Characters(Start:=x, Length:=10).Font.Color = RGB(192, 0, 0)
     End If
 Feuil1.Range("AB" & i + k).ClearContents
End Sub
 

Pièces jointes

  • rouge.xlsm
    19.7 KB · Affichages: 20

soan

XLDnaute Barbatruc
Inactif
Bonjour Ben, sylvanu,

Je propose cette petite optimisation :
VB:
Option Explicit

Dim txt$, lig&

Private Sub Job(col%, dv&)
  Dim cel As Range, chn$, p%: Set cel = Feuil1.Cells(lig + dv, col)
  chn = cel.Value: p = InStr(1, chn, txt, 1): If p = 0 Then Exit Sub
  With cel.Characters(p, Len(chn)).Font
    .Bold = -1: .Color = RGB(192, 0, 0)
  End With
End Sub

Sub ROUGE()
  Const Q As Byte = 17, I As Byte = 9: lig = 127: Application.ScreenUpdating = 0
  Do: lig = lig + 1: Loop Until Feuil1.Cells(lig, 2).Text = "GÉNÉRATEURS"
  txt = "Chaud": Job Q, 4: Job I, 10: Job I, 11: txt = txt & " seul"
  Job Q, 4: Job Q, 11: Job I, 10: Job I, 11
End Sub
Ce code VBA ne se sert pas de la colonne AB ➯ dans ton fichier réel, tu peux la supprimer. ;)
Si tu passes mon code VBA dans la machine à laver, ça le rétrécira peut-être un peu plus ?


soan
 

Pièces jointes

  • rouge.xlsm
    18.2 KB · Affichages: 5
Dernière édition:

Discussions similaires

Réponses
7
Affichages
345
Réponses
17
Affichages
819

Statistiques des forums

Discussions
312 177
Messages
2 085 972
Membres
103 073
dernier inscrit
MSCHOE16