Selection automatique dernière ligne vide

ssassam

XLDnaute Occasionnel
Bonjour tout le monde,

Svp j'ai enregistré une macro de tri , je souhaite qu'elle récupère automatiquement la dernière ligne vide de mon tableau.



Code:
Sub TRI()

    Columns("A:O").Select
    ActiveWorkbook.Worksheets("HIST").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("HIST").Sort.SortFields.Add Key:=Range("D2:D65"), _ 'ICI SÉLECTION AUTOMATIQUE
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("HIST").Sort
        .SetRange Range("A1:O65") 'ICI SÉLECTION AUTOMATIQUE
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
End Sub


Merci beaoucoup.
 

Jack2

XLDnaute Occasionnel
Re : Selection automatique dernière ligne vide

Bonjour,

DerLigne= Range("A" & Rows.Count).End(xlUp).Row + 1

Dans with ActiveWorkbook.Worksheets("HIST").Sort :
DerLigne= .Range("A" & Rows.Count).End(xlUp).Row + 1

A+ Jack2
 

ssassam

XLDnaute Occasionnel
Re : Selection automatique dernière ligne vide

Merci Jack2 , ça marche pas

Je souhaite aussi automatisé la Add Key:=Range("D2: D65") pour qu'il redevienne adaptable a l'importe quel tableau.


Code:
Sub TRI()


    Columns("A:O").Select
    ActiveWorkbook.Worksheets("HIST").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("HIST").Sort.SortFields.Add Key:=Range("D2:D65"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("HIST").Sort
    DerLigne = .Range("A" & Rows.Count).End(xlUp).Row + 1
        '.SetRange Range("A1:O65")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
   
End Sub
 

Jack2

XLDnaute Occasionnel
Re : Selection automatique dernière ligne vide

Bonjour ssassam,

La formule que je t'ai donnée ne fonctionne pas après l'instruction de tri (.Sort), il faut la placer avant :
Code:
With ActiveWorkbook.Worksheets("HIST")
    DerLigne = .Range("A" & Rows.Count).End(xlUp).Row + 1
    .Sort
Pour comprendre ce à quoi tu souhaites arriver, ça serait bien que tu joignes un fichier sans valeurs persos et que tu expliques ce que tu veux faire avec situation avant code puis la situation désirée après macro.

A+ Jack2
 

Statistiques des forums

Discussions
312 217
Messages
2 086 353
Membres
103 196
dernier inscrit
N-TR86