MFC par rapport au chiffre contenu dans la cellule d'une colonne
Résolu
agathe182
Messages postés
49
Statut
Membre
-
f894009 Messages postés 17417 Date d'inscription Statut Membre Dernière intervention -
f894009 Messages postés 17417 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'essaie d'appliquer une MFC dès lors que les chiffres 1 à 6 se trouvent dans la colonne B de mon tableau. Pour cela, j'ai essayé d'utiliser la fonction .find mais je n'arrive pas à la faire fonctionner... Voici mon code :
Des idées ?
Merci par avance pour votre aide :)
J'essaie d'appliquer une MFC dès lors que les chiffres 1 à 6 se trouvent dans la colonne B de mon tableau. Pour cela, j'ai essayé d'utiliser la fonction .find mais je n'arrive pas à la faire fonctionner... Voici mon code :
Sub MFC_alerts()
' MFC sur les alertes
Dim i As Integer
derniereligne = Range("B50000").End(xlUp).Row
For i = 3 To derniereligne
' Alerte 1
If Range("B" & i).Find("1", Lookat:=xlPart) Then
Range("i26,i27").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
' Alerte 2
ElseIf Range("i2").Find("2", Lookat:=xlPart) Then
Range("i30").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
'Alerte 3
ElseIf Range("i2").Find("3", Lookat:=xlPart) Then
Range("i19,i22").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
'Alerte 4
ElseIf Range("i2").Find("4", Lookat:=xlPart) Then
Range("i37").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
'Alerte 5
ElseIf Range("i2").Find("5", Lookat:=xlPart) Then
Range("i33").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
'Alerte 6
ElseIf Range("i2").Find("6", Lookat:=xlPart) Then
Range("i41").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 192
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Else
End If
Next i
End Sub
Des idées ?
Merci par avance pour votre aide :)
3 réponses
-
Bonjour,
Pourquoi du VBA pour ces "MFC" ?? -
bonjour
F89 :excuse l'incruste
comme il existe un coce pour enlever ces vraies-fausses MFCOption Explicit
'--------------------------------------------
Sub vraie_fausse_mfc()
Dim Derlig As Integer, Cptr As Integer, D_mfc As Object, T_colB, Ref As Byte
Application ScreenUpdating = False
Derlig = Columns("B").Find(what:="*", searchdirection:=xlPrevious).Row
Set D_mfc = CreateObject("scripting.dictionnary")
For Cptr = 1 To 6
D_mfc.Add Cptr, ""
Next
T_colB = Application.Transpose(Range("B1:B" & Derlig))
For Cptr = 1 To Derlig
Ref = T_cob(Cptr)
If D_mfc.exists(Ref) Then
Select Case Ref
Case 1
With Range(Cells(26, Cptr), Cells(27, Cptr))
.Interior.Color = 192
.Font.Color = xlThemeColorDark1
End With
Case 2
'.......etc
End Select
End Sub
nota
xlThemeColorDark1 correspond à la couleur par défaut d'excel-
-
-
Re,
Code modifie
Sub MFC_alerts() ' MFC sur les alertes Dim i As Integer derniereligne = Range("B50000").End(xlUp).Row For i = 3 To derniereligne Alerte = Range("B" & i) ' Alerte 1 '- Si ("B" & i) contient 1 : changer la couleur de i26 et i27 (donc la colonne Z et AA, ligne i) If Alerte Like "*1*" Then Range("Z" & i & ",AA" & i).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 192 .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End If ' Alerte 2 '- Si ("B" & i) contient 2 : changer la couleur de i30 (colonne AD, ligne i) If Alerte Like "*2*" Then Range("AD" & i).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 192 .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End If 'Alerte 3 '- Si ("B" & i) contient 3 : changer la couleur de i19 et i22 (colonne S et V, ligne i) If Alerte Like "*3*" Then Range("S" & i & ",V" & i).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 192 .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End If 'Alerte 4 '- Si ("B" & i) contient 4 : changer la couleur de i38 (colonne AL, ligne i) If Alerte Like "*4*" Then Range("AL" & i).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 192 .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End If 'Alerte 5 '- Si ("B" & i) contient 5 : changer la couleur de i35 (Colonne AI, ligne i) If Alerte Like "*5*" Then Range("AI" & i).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 192 .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End If 'Alerte 6 '- Si ("B" & i) contient 6 : changer la couleur de i43 (colonne AQ, ligne i) If Alerte Like "*6*" Then Range("AQ" & i).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 192 .TintAndShade = 0 .PatternTintAndShade = 0 End With With Selection.Font .ThemeColor = xlThemeColorDark1 .TintAndShade = 0 End With End If Next i End Sub -
-
-
-
