Sub CopierCollerTS()
    Dim wsRecap As Worksheet
    Dim wsImport As Worksheet
    Dim tRecap As ListObject
    Dim tImport As ListObject
    Dim i As Long
    Dim tableauDonnees() As Variant
    Dim lignes As Long
    
    Set wsRecap = ThisWorkbook.Sheets("t_Recap")
    Set wsImport = ThisWorkbook.Sheets("t_Import")
    
    Set tRecap = wsRecap.ListObjects("t_Recap")
    Set tImport = wsImport.ListObjects("t_Import")
    
    ' Vérifier si le tableau source contient des données
    If tRecap.DataBodyRange Is Nothing Then
        MsgBox "Le tableau t_Recap ne contient pas de données.", vbExclamation
        Exit Sub
    End If
    
    ' Définir la taille du tableau en fonction du nombre de lignes du tableau source
    lignes = tRecap.DataBodyRange.Rows.Count
    ReDim tableauDonnees(1 To lignes, 1 To 10) ' 10 colonnes à copier
    ' Charger les données de t_Recap dans le tableau
    For i = 1 To lignes
        tableauDonnees(i, 1) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Code agent").Index).Value
        tableauDonnees(i, 2) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("NOM Prénom").Index).Value
        tableauDonnees(i, 3) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Date").Index).Value
        tableauDonnees(i, 4) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Total heures matin").Index).Value
        tableauDonnees(i, 5) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Total heures après-midi").Index).Value
        tableauDonnees(i, 6) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Total heures soir").Index).Value
        tableauDonnees(i, 7) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Total heures jour").Index).Value
        tableauDonnees(i, 8) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Total heures Sup").Index).Value
        tableauDonnees(i, 9) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Nbre de plages").Index).Value
        tableauDonnees(i, 10) = tRecap.DataBodyRange.Cells(i, tRecap.ListColumns("Commentaires").Index).Value
    Next i
    
    If tImport.DataBodyRange Is Nothing Then
        ' Si t_Import est vide, ajouter la première ligne avant de redimensionner
        tImport.ListRows.Add
    End If
    
    ' Coller les données dans t_Import en redimensionnant correctement le tableau
    tImport.DataBodyRange.Resize(lignes, 10).Value = tableauDonnees
    
    MsgBox "Les données ont été copiées avec succès à partir de t_Recap vers t_Import !", vbInformation
    
End Sub