Sub Transfert()
' Déclaration des variables
Application.ScreenUpdating = False
Dim ligne As Integer
Dim i As Integer
'Dim derl, ColFin As String
' Initialisation de la variable ligne à 2 (la ligne 1 est la ligne des titres)
ligne = 2
ColFin = 8
cheminfichier = Application.GetOpenFilename("Fichiers Excels (*.xlsx), *.xlsx")
' Si on clique sur Annuler dans la fenêtre, on sort de la boucle
If cheminfichier = False Then
ThisWorkbook.Save
ThisWorkbook.Close
Application.Quit
End If
' Ouverture du classeur source
Workbooks.Open (cheminfichier)
' Récupération du nom du classeur + extension
For i = Len(cheminfichier) To 1 Step -1
If Mid(cheminfichier, i, 1) = "\" Then Exit For
Next
nomfichier = Mid(cheminfichier, i + 1, Len(cheminfichier))
'Stop
derl = Cells(65536, 1).End(xlUp).Row
derldest = Workbooks(ThisWorkbook.Name).Sheets("commande").Cells(65536).End(xlUp).Row + 1
ActiveSheet.Range(Cells(2, 1), Cells(derl, ColFin)).Copy Destination:=Workbooks(ThisWorkbook.Name).Sheets("commande").Range("A" & derldest)
' Copie des valeurs entre les classeurs
'ThisWorkbook.Sheets("Commande").Range("A4:Q4") = Workbooks(nomfichier).Sheets("Commande").Range("A2:Q2").Value
'ThisWorkbook.Sheets("Commande").Range("A5:Q5") = Workbooks(nomfichier).Sheets("Commande").Range("A3:Q3").Value
' Fermeture du classeur source
Workbooks(nomfichier).Close 0
' Incrémentation du numéro de ligne
ligne = ligne + 1
Application.ScreenUpdating = True
MsgBox (" X lignes copiées") 'si possible afficher le nombre de lignes copiées
End Sub