Sélectionner chaque ligne avec une boucle

Résolu
Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   -  
Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Voici mon code :

Sub Macro1()
Dim WTF As Long, DERLI As Long
DERLI = Sheets(2).Range("A65536").End(xlUp).Row
For WTF = 4 To DERLI
Sheets(2).Range("A4" & WTF).Row.Select

    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Next WTF
End Sub


Il consiste à prendre chaque ligne et faire un encadré en bas et en haut (je ne veut pas les encadrés à droite et à gauche.

Mais il ne marche pas...

Merci.
A voir également:

3 réponses

Frenchie83 Messages postés 2240 Date d'inscription   Statut Membre Dernière intervention   338
 
Bonjour
Avec une boucle
Sub Macro1()
    Application.ScreenUpdating = False
    Dim WTF As Long, DERLI As Long
    DERLI = Sheets(2).Range("A65536").End(xlUp).Row
    For WTF = 4 To DERLI + 1
        Sheets(2).Range("A" & WTF & ":D" & WTF).Select
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
    Next WTF
End Sub


sans boucle
Sub Macro2()
    Application.ScreenUpdating = False
    Dim DERLI As Long
    DERLI = Sheets(2).Range("A65536").End(xlUp).Row
    Sheets(2).Range("A4:D" & DERLI).Select
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
End Sub

Ne connaissant pas les limites des colonnes, j'ai pris la colonne D comme dernière colonne, a vous de l'adapter
cdlt
0
Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   61
 
Merci beaucoup !

La sélection me posait problème...

Merci encore.

Cordialement,
0
michel_m Messages postés 16602 Date d'inscription   Statut Contributeur Dernière intervention   3 314
 
Bonjour,
la solution est facile mais tu m'as sérieusement déçu hier en ne daignant pas jeter un oeil sur la solution que je te proposais....
donc: ciao
0
Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   61
 
J'ai mis le sujet en résolu hier car je suis sorti du travail et je ne suis pas retourné sur ccm. Comme le code marchait parfaitement, j'ai préféré le faire. Ca ne m'empêche pas du tout de lire ton code et de le tester en ce moment même. Je suis juste incapable de le comprendre, comme je l'ai expliqué dans le sujet en question.
0