Here is my code, it works when I use 1 range but if I use 2 or more it does not work. I dont really know how to fix my code. Any help would be very appreciated
Function CUSTOMAVERAGE(rng As Range)
Dim cell As Range, suma As Double, sk As Double, i As Double, vidurkis As Double, max As Double, dup As Double, dupp As Double, down As Double, downn As Double, text1 As String
suma = 0
For Each cell In rng
suma = suma + cell.Value
sk = sk + 1
Next cell
vidurkis = suma / sk
max = 0
For Each cell In rng
If max < cell.Value Then
max = cell.Value
End If
Next cell
max = max
min = max
For Each cell In rng
If min > cell.Value Then
min = cell.Value
End If
Next cell
min = min
dupp = 0
dup = 0
sk = 0
For Each cell In rng
If vidurkis < cell.Value Then
dupp = dupp + cell.Value
sk = sk + 1
End If
Next cell
dup = dupp / sk
downn = 0
down = 0
sk = 0
For Each cell In rng
If vidurkis > cell.Value Then
downn = downn + cell.Value
sk = sk + 1
End If
Next cell
down = downn / sk
text1 = "V=" & CStr(vidurkis) & " Min=" & CStr(min) & " Max=" & CStr(max) & " Dup=" & CStr(dup) & " Ddown=" & CStr(down)
CUSTOMAVERAGE = text1
End Function
Any example would be great too.