Microsoft 365 ajouter des lignes vides

Pilou59

XLDnaute Nouveau
Bonjour le forum,
J'aimerai ajouter des lignes numérotées manquant dans la colonne A a la suite par un bouton, ligne qui va jusque 57400


50000
50001
50002
exct

Liste du personnel pour CSE
MatNomPrenomDate entDate SortVU
50000NOM001PRENOM00125/06/1974
50001
50687NOM003PRENOM00331/01/197728/02/2021


Merci de votre aide.
 

Pièces jointes

  • Copie de Liste du personnel.xlsx
    43 KB · Affichages: 7

AtTheOne

XLDnaute Accro
Supporter XLD
Bonjour a toutes & à tous, bonjour @Pilou59
Voilà une macro qui fait l'affaire :
Enrichi (BBcode):
Sub compléter()
    Dim Wsh As Worksheet, Dc As Object, Tb, NbLgn As Long, NbCol As Long, LgnBas As Long, NbPlus As Long
    
    Set Wsh = ThisWorkbook.Worksheets("Liste du personnel pour CSE")
    
    Set Dc = CreateObject("Scripting.Dictionary")
    For i = 50000 To 57400: Dc(i) = i: Next
    
    With Wsh
        LgnBas = .Cells(.Rows.Count, 1).End(xlUp).Row
        Tb = .Range(.Cells(2, 1), .Cells(LgnBas, 1))
        NbLgn = UBound(Tb)
        NbCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End With
    
    With WorksheetFunction
        Tb = .Unique(.Sort(Tb))
    End With
    For i = 1 To UBound(Tb)
        Dc.Remove (Tb(i, 1))
    Next
    NbPlus = Dc.Count
    With Wsh
        .Cells(LgnBas + 1, 1).Resize(NbPlus) = WorksheetFunction.Transpose(Dc.Keys)
        With .Sort
            .SortFields.Clear
            .SortFields.Add Key:=Wsh.Cells(1, 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            .SetRange Wsh.Cells(1, 1).Resize(NbLgn + NbPlus + 1, NbCol)
            .Header = xlYes
            .Apply
        End With
    End With
    With Wsh.Cells(2, 1).Resize(NbLgn + NbPlus, NbCol)
        .Interior.Color = RGB(247, 247, 247)
        .Borders.LineStyle = xlContinuous
        .Borders.Color = RGB(221, 221, 221)
    End With
    Wsh.Cells(2, 1).Resize(NbLgn + NbPlus, 3).HorizontalAlignment = xlLeft
    With Wsh.Cells(2, 4).Resize(NbLgn + NbPlus, 2)
        .NumberFormat = "dd/mm/yyyy"
        .HorizontalAlignment = xlCenter
    End With
End Sub
Elle ajoute également la mise en forme ...
Voir le fichier joint
Amaicalement
Alain
 

Pièces jointes

  • Liste du personnel.xlsm
    54.1 KB · Affichages: 4

Statistiques des forums

Discussions
312 489
Messages
2 088 853
Membres
103 975
dernier inscrit
denry