Bonjour Jess,
Voici un premier essai pas testé... Le code porte sur toute la zone utilisée de la feuille active (il faudra donc adapter les références de la source).
Tout d'abord, on considère que les données sont triées par prénom ici (si ce n'est pas le cas, il faudra ajouter une macro de tri avant d'entamer les transferts).
Ici, le prénom est supposé se trouver en colonne 1 et les fichiers de destination sont censés se trouver dans le dossier Téléchargements. Lorsqu'un fichier n'existe pas, il est créé :
Sub test()
application.screenupdating = false
with activesheet.usedrange
t = .value
thead = .rows(1).value
i = 2
do while i <= ubound(t)
chemin$ = environ("userprofile") & "\Downloads\" & t(i, 1) & ".xlsx"
if t(i, 1) <> t(i - 1, 1) then
redim temp(1 to ubound(t), 1 to ubound(t, 2)): n = 0
do
n = n + 1
for k = lbound(t, 2) to ubound(t, 2)
temp(n, k) = t(i, k)
next k
i = i + 1
if i > ubound(t) then exit do
loop while t(i, 1) = t(i - 1, 1)
i = i - 1
with GetClasseur(chemin)
with .sheets(1)
if dir(chemin) = "" then .rows(1).resize(1, ubound(thead, 2)).value = thead
nvl = .cells(.rows.count, 1).end(xlup).row + 1
.cells(nvl, 1).resize(n, ubound(t, 2)).value = temp
end with
application.displayalerts = false
.saveas chemin, 51
.close true
application.displayalerts = true
end with
end if
i = i + 1
loop
end with
application.screenupdating = true
end sub
function GetClasseur(spath$) as workbook
if dir(spath) = "" then
Set GetClasseur = workbooks.add
else
set GetClasseur = workbooks.open(spath)
end if
end function
Cdlt,