Sub Macocotte()
Dim ws As Worksheet
Dim lgRow As Long
Dim nom As String
With ThisWorkbook
'
' Vérifier l'éxistence de la feuille 'Modèle'
Set ws = getSheetByName("Modèle", False)
If ws Is Nothing Then
MsgBox "Opération interrompue : la feuille 'Modèle' n'existe pas dans le fichier", vbExclamation, "Macro : Macocotte"
GoTo FIN
End If
'
' important pour les lignes suivantes
' Réinitialiser la variable à nothing
Set ws = Nothing
'
' Travailler sur la plage de lignes et colonnes contigues A1
With .Sheets("Fichier Origine").Range("A1").CurrentRegion
'
' Parcourir les lignes de la plage
For lgRow = 2 To .Rows.Count
'
' si un nom est présent en colonne 1
nom = Trim(.Cells(lgRow, 1))
If nom <> "" Then
'
' voir s'il existe une feuille à ce nom,
' éventuellement la créer
' et ensuite mettre à jour les données.
Set ws = getSheetByName(nom, True)
If Not ws Is Nothing Then
ws.Range("P5") = nom
ws.Range("P6") = .Cells(lgRow, 2)
ws.Range("D7") = .Cells(lgRow, 3)
ws.Range("E7") = .Cells(lgRow, 4)
ws.Range("G7") = .Cells(lgRow, 5)
ws.Range("J7") = .Cells(lgRow, 6)
ws.Range("K7") = .Cells(lgRow, 7)
ws.Range("L7") = .Cells(lgRow, 8)
End If
End If
Next
End With
End With
FIN:
End Sub