vba - How do I use 2 ranges in Excel -


here code, works when use 1 range if use 2 or more not work. dont know how fix code. appreciated

    function customaverage(rng range) dim cell range, suma double, sk double, double, vidurkis double, max double, dup double, dupp double, down double, downn double, text1 string   suma = 0 each cell in rng     suma = suma + cell.value     sk = sk + 1 next cell vidurkis = suma / sk    max = 0 each cell in rng     if max < cell.value     max = cell.value     end if next cell max = max  min = max each cell in rng     if min > cell.value     min = cell.value     end if next cell min = min  dupp = 0 dup = 0 sk = 0 each cell in rng     if vidurkis < cell.value     dupp = dupp + cell.value     sk = sk + 1     end if next cell dup = dupp / sk    downn = 0 down = 0 sk = 0 each cell in rng     if vidurkis > cell.value     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 great too.

try this:

option explicit  function customaverage(paramarray ranges())     dim rng range     dim part variant     dim cell range     dim double     dim suma double     dim sk double     dim min double     dim max double     dim vidurkis double     dim dup double     dim sk1 double     dim ddown double     customaverage = cverr(xlerrna)     set rng = nothing     each part in ranges         if typename(part) = "range"             if typename(rng) = "range"                 set rng = union(rng, part)             else                 set rng = part             end if         end if     next     if rng nothing exit function     suma = 0     sk = 0     min = 1.79769313486231e+308     max = -1.79769313486231e+308     each cell in rng         suma = suma + cell.value         sk = sk + 1         if min > cell.value min = cell.value         if max < cell.value max = cell.value     next     vidurkis = suma / sk     sk = 0     dup = 0     sk1 = 0     ddown = 0     each cell in rng         if vidurkis < cell.value             dup = dup + cell.value             sk = sk + 1         elseif vidurkis > cell.value             ddown = ddown + cell.value             sk1 = sk1 + 1         end if     next cell     if sk = 0 or sk1 = 0 exit function     dup = dup / sk     ddown = ddown / sk1     customaverage = "v=" & cstr(vidurkis) & " min=" & cstr(min) & " max=" & cstr(max) & " dup=" & cstr(dup) & " ddown=" & cstr(ddown) end function 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -