Function RecupNbHeuresInsertionArg(ByRef Cellule As Range) As Long Dim numcol As Integer Dim cell As Range Application.Volatile True numcol = Cellule.Value Dim som As Long som = 0
Sheets("Sem " & numcol).Range("B25:F44").Select
For Each cell In Selection
If cell.Interior.ColorIndex = 6 Then som = som + cell.Value
End If
Next cell
RecupNbHeuresInsertionArg = som
End Function
Je souhaite que cette fonction calcule la somme par couleur (ColorIndex = 6 est jaune) de l'onglet sélectionné par la variable d'entrée de ma fonction (cellule) sur une plage précise (ici B25:F44) de cet onglet.
Peut-être quelque chose d'évident m'échappe? Cette fonction me retourne une erreur #Valeur
J'espère être clair, merci d'avance pour votre aide précieuse
Sub Test()
MsgBox RecupNbHeuresInsertionArg(Worksheets("Sem 1").Range("B25:F44"))
End Sub
Function RecupNbHeuresInsertionArg(ByRef Plage As Range) As Long
Dim cel As Range
Dim som As Long
Application.Volatile True
For Each cel In Plage.Cells
If cel.Interior.ColorIndex = 6 Then som = som + Val(cel.Value)
Next cel
RecupNbHeuresInsertionArg = som
End Function