'### A adapter selon les dimensions de la plage ###
Private Enum Sens
Vertical = 41 'concaténation nb de lignes + 1 colonne = 41
Horizontal = 14 'concaténation nb de colonnes + 1 ligne = 14
BigDimension = 4 'la plus grande dimension ligne ou colonne
End Enum
'##################################################
'/// Si, par exemple, vous voulez travailler sur une plage d'1 sur 8
'/// Private Enum Sens
'/// Vertical = 81
'/// Horizontal = 18
'/// BigDimension = 8
'/// End Enum
Function Classe2(Plage As Range) As Long
Dim var
Dim Direction
Dim x&
Dim y&
Dim i&
Dim j&
Dim tempo&
Dim bool
Dim Total&
var = Plage
If Not IsArray(var) Then Exit Function
Direction = CLng(UBound(var, 1) & UBound(var, 2))
If Direction = Sens.Horizontal Then
x& = 1
y& = Sens.BigDimension
ElseIf Direction = Sens.Vertical Then
x& = Sens.BigDimension
y& = 1
Else
Classe2 = Error
Exit Function
End If
For i& = 1 To x&
For j& = i To y&
Total& = Total& + var(i&, j&)
Next j&
Next i&
If Total& >= 10 Then
For i& = x& To 1 Step -1
For j& = y& To 1 Step -1
tempo& = var(i&, j&)
If Not bool Then tempo& = tempo& - 1
If tempo& > 0 Then
If Direction = Sens.Horizontal Then
Classe2 = j&
ElseIf Direction = Sens.Vertical Then
Classe2 = i&
End If
Exit Function
ElseIf tempo& = 0 Then
bool = True
End If
Next j&
Next i&
ElseIf Total& >= 6 Then
For i& = x& To 1 Step -1
For j& = y& To 1 Step -1
If var(i&, j&) > 0 Then
If Direction = Sens.Horizontal Then
Classe2 = j&
ElseIf Direction = Sens.Vertical Then
Classe2 = i&
End If
Exit Function
End If
Next j&
Next i&
ElseIf Total& < 6 Then
Classe2 = 0
End If
End Function