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
|
Option Explicit
Function AgentPoste(ByVal NomFeuilleMois As String, ByVal TitreFeuille As Long, ByVal JourChoisi As Date, ByVal PosteChoisi As String, ByVal IndiceChoisi As Integer) As String
Dim FeuilleMois As Worksheet
Dim I As Long
Dim ColonneMois As Long, DerniereColonne As Long, DerniereLigne As Long, ColonneAgent As Long
Dim AireJournee As Range, CellulePoste As Range
Dim IndiceEnCours As Integer
Application.Volatile
Set FeuilleMois = Sheets(NomFeuilleMois)
With FeuilleMois
ColonneAgent = 1
DerniereLigne = .Cells(.Rows.Count, ColonneAgent).End(xlUp).Row
DerniereColonne = .Cells(TitreFeuille, .Columns.Count).End(xlToLeft).Column
ColonneMois = 0
For I = 1 To DerniereColonne
If .Cells(TitreFeuille, I) = JourChoisi Then ColonneMois = I
Next I
If ColonneMois = 0 Then Exit Function
Set AireJournee = .Range(.Cells(TitreFeuille + 1, ColonneMois), .Cells(DerniereLigne, ColonneMois))
If WorksheetFunction.CountIf(AireJournee, PosteChoisi) > 0 Then
IndiceEnCours = 0
AgentPoste = ""
For Each CellulePoste In AireJournee
If CellulePoste = PosteChoisi Then
IndiceEnCours = IndiceEnCours + 1
If IndiceEnCours = IndiceChoisi Then
AgentPoste = CellulePoste.Offset(0, ColonneAgent - ColonneMois)
Exit For
End If
End If
Next CellulePoste
End If
Set AireJournee = Nothing
End With
Set FeuilleMois = Nothing
End Function |
Partager