Function operation(Otype$, Plage As Variant, valeur As Double)
With Application
.Volatile
Select Case Otype
Case Is = "A"
operation = .Sum(Plage) + valeur
Case Is = "S"
operation = .Sum(Plage) - valeur
Case Is = "M"
operation = .Sum(Plage) * valeur
Case Is = "D"
operation = .Sum(Plage) / valeur
Case Else
End
End Select
End With
End Function
Sub Test()
[A1:A3] = 12
MsgBox operation("A", Range("A1:A3"), 3)
MsgBox operation("S", Range("A1:A3"), 4)
MsgBox operation("M", Range("A1:A3"), 5)
MsgBox operation("D", Range("A1:A3"), 6)
End Sub
Option Explicit
Function DIVISION(valeur As Variant, Plage As Variant)
Dim Ligne As Long
Application.Volatile
Ligne = [G2] \ [G3] \ [G4] \ [G5]
Plage = Ligne
On Error Resume Next
DIVISION = Application.Sum(Ligne)
End Function
Function Operation(Otype$, Plage, valeur#)
Dim aux$, i As Byte
aux = "A+S-M*D/"
i = InStr(aux, UCase(Left(Otype, 1)))
Operation = Evaluate(Application.Sum(Plage) & Mid(aux, i + 1, 1) & valeur)
If IsError(Operation) Then Operation = "" 'facultatif
End Function
Function Operation(Otype$, Plage)
Dim aux$, i As Byte, operateur$
Plage = Plage
If UBound(Plage) > 1 Then Plage = Application.Transpose(Plage)
aux = "A+S-M*D/"
i = InStr(aux, UCase(Left(Otype, 1)))
operateur = Mid(aux, i + 1, 1)
Operation = Evaluate(Join(Plage, operateur))
If IsError(Operation) Then Operation = "" 'facultatif
End Function