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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
Function sommedB(ParamArray CellAddress()) As Variant
' Declaration of function variables.
Dim Temp As Variant
Dim TheArray() As Variant
Dim Count As Integer, Ver As Integer
Dim W As Integer, X As Integer, Y As Integer, Z As Integer
' Initialize the Count variable.
Count = 1
' Set the variable Ver = 0 if the version of Microsoft Excel is
' greater than 8 (8 is Microsoft Excel 97 for Windows).
If Left(Application.Version, Len(Application.Version) - 1) >= 8 Then
Ver = 0
Else
Ver = 1
End If
' Set variable X from Ver to the total number of arguments in
' the CellAddress array.
For X = Ver To UBound(CellAddress, 1)
' Temp equals the first element of the CellAddress array.
Set Temp = CellAddress(X)
' Test Temp to see whether it is an array.
If IsArray(Temp) Then
' If Temp is an array, set Y from 1 to the total number
' arguments in the Temp array's first dimension.
For Y = 1 To UBound(Temp.Value, 1)
' If Temp is an array, set Z from 1 to the total number
' arguments in the Temp array's second dimension.
For Z = 1 To UBound(Temp.Value, 2)
' ReDimension TheArray, Preserving any existing
' values, from 1 to Count.
ReDim Preserve TheArray(1 To Count)
' TheArray, element Count equals Temp, element Y in the
' first dimension by element Z in the second dimension.
TheArray(Count) = Temp(Y, Z).Value
' Increment the Count variable by one.
Count = Count + 1
Next Z
Next Y
' If Temp is not an array, proceed from here.
Else
' ReDimension TheArray, preserving any existing
' values, from 1 to Count.
ReDim Preserve TheArray(1 To Count)
' TheArray element Count equals Temp.
TheArray(Count) = Temp
' Increment the Count variable by one.
Count = Count + 1
' End the block If statement.
End If
Next X
som = 0
For W = 1 To UBound(TheArray, 1)
som = som + 10 ^ (TheArray(W) / 10)
Next W
sommedB = 10 * Application.Log10(som)
End Function |
Partager