1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Sub Test_Copie()
Dim WshN As String
Dim InpRng As Range, Cl As Range
Dim ClContAR As Variant
Set InpRng = ThisWorkbook.Worksheets("Adresse mails").Range("A2").CurrentRegion
Debug.Print InpRng.AddressLocal
For Each Cl In InpRng.Columns(1).Cells
If Not (IsEmpty(Cl)) Then
ClContAR = Split(Cl.Value, " - ", , vbTextCompare) ' On Split la valeur sur le séparateur " - "
If UBound(ClContAR, 1) <> LBound(ClContAR, 1) Then 'On vérifie que le split a fonctionné = au moins deux éléments
WshN = LCase(ClContAR(LBound(ClContAR, 1)))
On Error Resume Next
If IsObject(Worksheets(WshN)) = False Then ' Si la feuille n'existe pas, on la crée
ThisWorkbook.Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = WshN
End If
Debug.Print Cl.Row; InpRng.Rows(Cl.Row).Address
InpRng.Rows(Cl.Row).EntireRow.Copy Destination:=Worksheets(WshN).Range("A1")
End If
End If
Next Cl
End Sub |
Partager