Bonjour,

J'ai un problème avec la fonction que j'ai codé. Quand je l'écris dans une cellule avec ses arguments de date type "jj/mm/aaaa", la fonction renvoie une erreur #VALEUR! et un message "Le type de données d'une valeur utilisée dans la formule est incorrect". Quand je regarde le détail, je m'aperçois que les deux arguments passés ne sont pas des dates mais la division des trois nombres !!!

Voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Option Explicit
 
Function calculJoursNonOuvres(dateDebut As Variant, dateFin As Variant) As Integer
    Application.Volatile
    Application.Calculation = xlCalculationManual
Dim datePlanning As Range
    Dim adresseDebut As String
    Dim adresseFin As String
    Dim Plage As Range
    Dim cell, cpt
    cpt = 0
 
    For Each datePlanning In Worksheets("Planning").Range("C4:BU34")
        If datePlanning.Value = dateDebut Then
            adresseDebut = datePlanning.Address
        End If
        If datePlanning.Value = dateFin Then
            adresseFin = datePlanning.Address
        End If
    Next datePlanning
 
    Plage = adresseDebut & ":" & adresseFin
    For Each cell In Plage
        If cell.Interior.ColorIndex = 33 Then
            cpt = cpt + 1
        End If
    Next cell
    calculJoursNonOuvres = cpt
    Application.Calculation = xlCalculationAutomatic
End Function
Je n'y comprends rien. Pouvez vous m'aider svp ?
Merci d'avance.
Cordialement.