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 36 37 38 39 40 41 42 43 44
| Sub yaMaestro()
Dim iAsn14 As Integer
Dim iASn13 As Integer
Dim iPos As Integer
Dim c As Range 'cellule lu
Dim bAsn13 As Boolean
'je considére que les 2 feuilles Asn13 et Asn14 existent et sont vides.
' sinon il faudrai les crée ou initialiser les 2 variables iAsn13 et iAsn14
Dim stMotif As String 'Memo du dernier Motif mémorisé.
Dim r As Range
'La feuille liste contient ' plusieurs centaines de lignes
Set r = ThisWorkbook.Sheets("liste").Range("A1").CurrentRegion
For Each c In r 'Parcours les cellules de la colonne A
iPos = InStr(c, "Motif=")
If iPos > 0 Then 'Nouvelle chaine motif
If stMotif <> "" Then ' Le 1° motif l'on ne fait rien
If bAsn13 Then
iASn13 = iASn13 + 1
ThisWorkbook.Sheets("ASn13").Cells(iASn13, 1) = stMotif
Else
iAsn14 = iAsn14 + 1
ThisWorkbook.Sheets("ASn14").Cells(iAsn14, 1) = stMotif
End If
bAsn13 = False
End If
stMotif = Mid(c, iPos + 6, InStr(iPos, c, " ") - iPos - 6)
End If
If InStr(c, "ASN13") > 0 Then bAsn13 = True
Next
' pose du dernier :
If stMotif <> "" Then ' Le 1° motif l'on ne fait rien
If bAsn13 Then
iASn13 = iASn13 + 1
ThisWorkbook.Sheets("ASn13").Cells(iASn13, 1) = stMotif
Else
iAsn14 = iAsn14 + 1
ThisWorkbook.Sheets("ASn14").Cells(iAsn14, 1) = stMotif
End If
bAsn13 = False
End If
End Sub |
Partager