Public Function ArrayFromRange(ByVal Target As Range) As Variant
'Helper function that returns an array from a range with the correct dimensions.
'This fixes the issue of single values not returning as an array, and when a 2 dimension array is returned, when it only has 1 dimension of data.
'Arrayx = ArrayFromRange(ws.Range("A1"))
'vARE = ArrayFromRange(Range("tous"))
Select Case True
Case Target.Cells.Count = 1 ' Single cell
ArrayFromRange = Array(Target.Value)
Case Target.Rows.Count = 1 ' Single Row
ArrayFromRange = Application.Transpose(Application.Transpose(Target.Value))
Case Target.Columns.Count = 1 ' Single Column
ArrayFromRange = Application.Transpose(Target.Value)
Case Else ' Multi dimension array
ArrayFromRange = Target.Value
End Select
End Function
Function M_CompteToday(ListA As Range)
Application.Volatile
Dim n%, i%, LgA%, x!, dat As String
Dim a() As String
Dim MatA As Variant, cel As Variant
MatA = ArrayFromRange(ListA)
LgA = ListA.Count
ReDim a(1 To LgA)
''*******************************************
n = 0
For Each cel In MatA 'construit variable de la colonne liste A (a)
n = n + 1
a(n) = Format(cel, "dd mmmm yy")
Next cel
''*******************************************TRT CONDITIONS
For i = 1 To LgA
If a(i) = Format(Now(), "dd mmmm yy") Then x = x + 1
Next i
''*******************************************
M_CompteToday = x
End Function