Macro S'executant mal

  • Initiateur de la discussion Initiateur de la discussion F2T
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

F2T

XLDnaute Occasionnel
Bonjour,

la macro ci dessous tres longue pour mettre en forme: ne s'execute pas correctement.

Code:
    RANGE("J" & DERLIGNE).Select
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    



    RANGE("L" & DERLIGNE) = "-"


  RANGE("M" & DERLIGNE & ":N" & DERLIGNE).Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    




    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16776961
        .TintAndShade = 0
    End With
    



    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    



    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16744448
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    



    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With




    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With


With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    



With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16744448
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
   



    RANGE("P" & DERLIGNE & ":T" & DERLIGNE).Select
           Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    

With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    

With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16744448
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
   

With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    

With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With



    RANGE("K" & DERLIGNE).Select
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
   


 With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16776961
        .TintAndShade = 0
   

 End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    

With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16744448
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    


With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With



  
    

    RANGE("AE" & DERLIGNE & ":AG" & DERLIGNE).Select
        Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
   

 With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:="=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16744448
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
   

 With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
   

 With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    RANGE("U" & DERLIGNE).Select

    Selection.NumberFormat = "[h]:mm"
    Selection.Font.Bold = False
    Selection.Font.Bold = True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With


    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With





    RANGE("O" & DERLIGNE).Select
    Selection.NumberFormat = "[h]:mm"
    Selection.Font.Bold = False
    Selection.Font.Bold = True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With


    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

Excel deraille, se trompe de couleur ou de format sur certaine cellule.

Que faire?

Tks pour l'aide
 
Re : Macro S'executant mal

Bonjour,

vue la taille de la macro, je t'avoue que je n'ai pas le courage de capter ce qu'elle tente de faire et il me parait plus simple de reprendre le travail à zéro : dis-nous ce que tu souhaites faire et on te proposera un code, bien plus court que celui-ci pour ce que j'en ai vu, qui répondra convenablement à te demande.
 
Re : Macro S'executant mal

Je souhaite mettre en forme plusieurs cellule.

J'en suis la, mais la syntaxe n'est pas correcte.

RANGE("Q16").Select
Selection.Copy
Sheets("REPORT").Select
RANGE("J" & DERLIGNE, "K" & DERLIGNE, "M" & DERLIGNE, "N" & DERLIGNE).Select
RANGE("N" & DERIGNE).Activate
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

RANGE("P,R & DERLIGNE,S & DERLIGNE,T & DERLIGNE").Select
RANGE("T & DERLIGNE").Activate
RANGE("P & DERLIGNE,R & DERLIGNE,S & DERLIGNE,T & DERLIGNE,AE & DERLIGNE,AF & DERLIGNE,AG & DERLIGNE").Select
RANGE("AG & DERLIGNE").Activate
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
RANGE("AF & DERLIGNE").Select
Application.CutCopyMode = False
Selection.NumberFormat = "0.00%"
 
Re : Macro S'executant mal

Basiquement, quelle syntaxe serait ok pour cette ligne:

RANGE("J" & DERLIGNE, "K" & DERLIGNE, "M" & DERLIGNE, "N" & DERLIGNE)

Bonjour quand meme Mr softmama. 🙂🙂 Ravi de vous voir.🙂🙂
 
Re : Macro S'executant mal

Bonsoir le fil 🙂,
"Basiquement", la syntaxe correcte est
Code:
Union(Range("J" & DERLIGNE), Range("K" & DERLIGNE), Range("M" & DERLIGNE), Range("N" & DERLIGNE))
Bonne soirée 😎
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
479
Réponses
9
Affichages
580
  • Question Question
Microsoft 365 comparaison texte
Réponses
5
Affichages
712
Réponses
11
Affichages
780
  • Question Question
Microsoft 365 colorer une plage
Réponses
2
Affichages
872
Réponses
22
Affichages
3 K
Réponses
2
Affichages
1 K
  • Résolu(e)
XL pour MAC Target
Réponses
9
Affichages
2 K
Retour