'### Constantes à adapter ###
Const FEUILLE_BDD As String = "bdd"
Const SYMBOLE As String = "x"
'############################
Sub ProcPMO(Numero As Long)
Dim S As Worksheet
Dim R As Range
Dim var As Variant
Dim LastRow&
Dim LastCol&
Dim i&
Dim j&
Dim cpt&
Dim ColNum&
Dim bool As Boolean
Dim T()
Set S = Sheets(FEUILLE_BDD)
LastRow& = S.[a65536].End(xlUp).Row
LastCol& = S.Range("iv" & LastRow& & "").End(xlToLeft).Column
Set R = S.Range(S.Cells(1, 1), S.Cells(LastRow&, LastCol&))
var = R
'--- Recherche de la colonne du numéro ---
For j& = 1 To LastCol&
If var(LastRow&, j&) = Numero Then
bool = True
ColNum& = j&
Exit For
End If
Next j&
If Not bool Then
MsgBox "Le numéro " & Numero & " ne figure pas dans la feuille " & FEUILLE_BDD
Exit Sub
End If
'--- Récupère les "Arret" marqués par le symbole (x en l'occurence) ---
For i& = 1 To LastRow&
If var(i&, ColNum&) = SYMBOLE Then
cpt& = cpt& + 1
ReDim Preserve T(1 To 1, 1 To cpt&)
T(1, cpt&) = var(i&, 1)
End If
Next i&
If cpt& = 0 Then 'on sort si aucune occurence n'a été trouvée
MsgBox "Aucune occurence n'a été trouvée pour le numéro " & Numero
Exit Sub
End If
'--- Crée une nouvelle feuille ---
Set S = Sheets.Add(after:=Sheets(Sheets.Count))
i& = 0
On Error Resume Next
Do
Err.Clear
S.Name = Numero & " (" & i& & ")"
i& = i& + 1
Loop Until Err = 0
On Error GoTo 0
'--- Inscrit les résultats dans une nouvelle feuille ---
Set R = S.Range("a3:b" & cpt& + 2 & "")
R = Application.WorksheetFunction.Transpose(T)
S.[a1] = "Numéro :"
S.[b1] = Numero
End Sub