• Initiateur de la discussion Initiateur de la discussion fr832
  • 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 !

fr832

XLDnaute Occasionnel
Bonsoir comment puis je modifier ce code afin d'y integrer la formule sous excel
=mod(ligne();2)) qui permet de colorer une ligne sur deux?

Par avance merci à tous

Code:
Sub mfclisting()
   
    Sheets("Listing").Select
   Range([A4], [A65535].End(xlUp)).Resize(, 12).Select
  
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlHairline
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlHairline
        .ColorIndex = xlAutomatic
    End With
    Range("a4").Select

End Sub

😕
 
Re : formule mod(ligne)

Bonsoir,

Un essai avec ce code (mais on doit pouvoir faire plus rapide ...)

Code:
Sub mfclisting()
 
With Sheets("Listing")
    Set plage = .Range([A4], [A65535].End(xlUp)).Resize(, 12)
    For Each c In plage
        If c.Row Mod 2 = 0 Then
            With c.Borders(xlEdgeLeft)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
            With c.Borders(xlEdgeTop)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
            With c.Borders(xlEdgeBottom)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
            With c.Borders(xlEdgeRight)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
            With c.Borders(xlInsideVertical)
                .LineStyle = xlContinuous
                .Weight = xlHairline
                .ColorIndex = xlAutomatic
            End With
            With c.Borders(xlInsideHorizontal)
                .LineStyle = xlContinuous
                .Weight = xlHairline
                .ColorIndex = xlAutomatic
            End With
        End If
    Next c
End With
End Sub

Bien à toi,

mth

Edit: bonsoir Bonzai 🙂
Arf, quand je disais qu'on pouvait faire plus rapide 🙂
tu as bien raison !
@ + 🙂
m
 
Dernière édition:
Re : formule mod(ligne)

Bonjour à tous
Un autre essai :
Code:
[B][COLOR=DarkSlateGray]Sub mfclisting()
Dim i As Byte, r As Range
  Application.Calculation = xlCalculationManual
  With Sheets("Listing").Range([A4], Cells(Rows.Count, 1).End(xlUp)).Resize(, 12)
    For i = 7 To 10
      With .Borders(i)
        .LineStyle = xlContinuous
        .Weight = xlThin
      End With
    Next i
    For i = 11 To 12
      With .Borders(i)
        .LineStyle = xlContinuous
        .Weight = xlHairline
      End With
    Next i
    For Each r In .Rows
      With r.Interior
        .ColorIndex = 35 * (1 - r.Row Mod 2)
        .Pattern = xlSolid
      End With
    Next r
  End With
  Application.Calculation = xlCalculationAutomatic
End Sub[/COLOR][/B]
ROGER2327
#4467


Jeudi 5 As 138 (Saint Van Meegeren, faussaire, SQ)
17 Brumaire An CCXIX
2010-W44-7T00:37:08Z
 
Dernière édition:
Re : formule mod(ligne)

Bonsoir Fr832,

Dans un premier temps, voici ton code simplifié et raccourci :
Code:
Sub mfclistingSimplifié()
   
Sheets("Listing").Range([a4], [A65535].End(xlUp)).Resize(, 12).Select
    
    For i = 1 To 4
        With Selection.Borders(i)
            .Weight = xlHairline
        End With
    Next i

    For j = 7 To 10
        With Selection.Borders(j)
            .Weight = xlThin
        End With
   Next j
    
[a4].Select

End Sub

J'ai supprimé les lignes :
-> .LineStyle = xlContinuous
-> .ColorIndex = xlAutomatic

Car il s'agit des valeurs prisent par défaut par excel, donc que tu écrive ces lignes de code ou non, ça ne change rien, sauf que c'est plus long (à écrire et à exécuter).

Voici maintenant ta macro complétée pour que les lignes pair soit coloriées :
Code:
Sub mfclistingSimplifiéEtComplété()
[COLOR="Green"]' Macro simplifié et complété le 07/11/2010 par Excel-lent
[/COLOR]
Dim Ligne As Long

Ligne = Sheets("Listing").[A65535].End(xlUp).Row

Sheets("Listing").Range([a4], Range("L" & Ligne)).Select

    For i = 1 To 4
        With Selection.Borders(i)
            .Weight = xlHairline
        End With
    Next i

    For j = 7 To 10
        With Selection.Borders(j)
            .Weight = xlThin
        End With
   Next j
   
[COLOR="Blue"][B]   For k = 4 To Ligne
       If k Mod 2 = 0 Then Sheets("Listing").Range(Range("A" & k), Range("L" & k)).Interior.ColorIndex = 15
   Next k[/B][/COLOR]

[a4].Select

End Sub

Bonne fin de soirée

Edition : bonsoir tout le monde
 
Dernière édition:
Re : formule mod(ligne)

bonjour excel lent merci pour ton aide également, pour ce qui est des lignes

.LineStyle = xlContinuous
.ColorIndex = xlAutomatic

c'est l'enregistreur de maccros qui les crée et comme je sais pas quoi enlever je les laisse.

Mais quand je vois effectivement vos codes simplifiés ça laisse rêveur.

Mes amitiés et encore merci pour tout
bon dimanche
 
- 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

Réponses
14
Affichages
484
M
Réponses
8
Affichages
2 K
Michelrib
M
T
  • Question Question
XL pour MAC Recherche date
Réponses
5
Affichages
2 K
tdenis
T
Réponses
8
Affichages
1 K
S
Réponses
4
Affichages
2 K
stage_ferrit
S
Retour