Option Explicit
Dim oWsBd As Worksheet 'feuille base de données
Public Function List_Cat() As String 'Liste catégorie
Dim i As Long
Dim vCol As Byte
Set oWsBd = Worksheets("Base de données")
vCol = 1 'colonne
List_Cat = "" 'valeur de la liste
'pour chaque ligne de la base de données
For i = 2 To oWsBd.Cells(oWsBd.Cells(Rows.Count, vCol).End(xlUp).Row, vCol).Row
'si la cellule rencontrée est différente de la précédente noter le nouvel item
Select Case List_Cat
Case "" '1ere occurence
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Cat = List_Cat & oWsBd.Cells(i, vCol)
Case Else 'suivantes
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Cat = List_Cat & "," & oWsBd.Cells(i, vCol)
End Select
Next i
Set oWsBd = Nothing
End Function
Public Function List_Nom(vCat As String) As String 'vCat est le paramètre d'entrée (nom de la catégorie)
Dim i As Long
Dim vCol As Byte
Set oWsBd = Worksheets("Base de données")
vCol = 2
List_Nom = ""
For i = 2 To oWsBd.Cells(oWsBd.Cells(Rows.Count, vCol).End(xlUp).Row, vCol).Row
If oWsBd.Cells(i, vCol - 1) = vCat Then 'si la catégorie est bien celle qu'on a mise en paramètre d'entrée
'si la cellule rencontrée est différente de la précédente noter le nouvel item
Select Case List_Nom
Case ""
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Nom = List_Nom & oWsBd.Cells(i, vCol)
Case Else
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Nom = List_Nom & "," & oWsBd.Cells(i, vCol)
End Select
End If
Next i
Set oWsBd = Nothing
End Function
Public Function List_Pre(vCat As String, vNom As String) As String
Dim i As Long
Dim vCol As Byte
Set oWsBd = Worksheets("Base de données")
vCol = 3
List_Pre = ""
For i = 2 To oWsBd.Cells(oWsBd.Cells(Rows.Count, vCol).End(xlUp).Row, vCol).Row
If oWsBd.Cells(i, vCol - 2) = vCat Then
If oWsBd.Cells(i, vCol - 1) = vNom Then
Select Case List_Pre
Case ""
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Pre = List_Pre & oWsBd.Cells(i, vCol)
Case Else
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Pre = List_Pre & "," & oWsBd.Cells(i, vCol)
End Select
End If
End If
Next i
Set oWsBd = Nothing
End Function
Public Function List_Des(vCat As String, vNom As String, vPre As String) As String
Dim i As Long
Dim vCol As Byte
Set oWsBd = Worksheets("Base de données")
vCol = 4
List_Des = ""
For i = 2 To oWsBd.Cells(oWsBd.Cells(Rows.Count, vCol).End(xlUp).Row, vCol).Row
If oWsBd.Cells(i, vCol - 3) = vCat Then
If oWsBd.Cells(i, vCol - 2) = vNom Then
If oWsBd.Cells(i, vCol - 1) = vPre Then
Select Case List_Des
Case ""
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Des = List_Des & oWsBd.Cells(i, vCol)
Case Else
If oWsBd.Cells(i, vCol) <> oWsBd.Cells(i - 1, vCol) Then List_Des = List_Des & "," & oWsBd.Cells(i, vCol)
End Select
End If
End If
End If
Next i
Set oWsBd = Nothing
End Function
Public Function List_Prx(vCat As String, vNom As String, vPre As String, vDes As String) As Long
Dim i As Long
Dim vCol As Byte
Set oWsBd = Worksheets("Base de données")
vCol = 5
List_Prx = 0
For i = 2 To oWsBd.Cells(oWsBd.Cells(Rows.Count, vCol).End(xlUp).Row, vCol).Row
If oWsBd.Cells(i, vCol - 4) = vCat Then
If oWsBd.Cells(i, vCol - 3) = vNom Then
If oWsBd.Cells(i, vCol - 2) = vPre Then
If oWsBd.Cells(i, vCol - 1) = vDes Then
List_Prx = oWsBd.Cells(i, vCol)
End If
End If
End If
End If
Next i
Set oWsBd = Nothing
End Function