excel vba - VBA writing code for standard deviation and Range -
i trying write function in vba calculate standard deviation , range of 3 numbers. if of numbers determined --- funtion should output --- answer. if 3 of them not --- standard deviation or range should calculated remaining number while ignoring --- number. numbers inputted user. here code have written range , standard deviation calculation. using built in excel ws function ignores inputs if not numbers able bypass tricky bit. visible have been unable code recognize when 3 --- register ---.
function calculate range -------------------------------
function range(paramarray observedvalues())
while observedvalues(i) = "---" range = "---" wend
max = application.worksheetfunction.max(observedvalues) min = application.worksheetfunction.min(observedvalues) range = max - min
end function
functions calculate standard deviation (multiple attempts)
first attempt
function sd(observedvaluea, observedvalueb, observedvaluec, observedmean)
if observedvaluea = "---" , observedvalueb = "---" , observedvaluec = "---" sd = "---" end if
if observedvaluea <> "---" = 1 x = observedvaluea - observedmean else = 0 x = 1 end if if observedvalueb <> "---" b = 1 y = observedvalueb - observedmean else b = 0 y = 1 end if if observedvaluec <> "---" c = 1 z = observedvaluec - observedmean else c = 0 z = 1 end if
sd = sqr((1 / (a + b + c)) * x ^ 2 * y ^ 2 * z ^ 2)
end function
second attempt
function sd(paramarray number_input())
while number_input = "---" sd = "---" wend sd = application.worksheetfunction.stdev(number_input)
end function
say 3 values compute sd of in a1:a3
function sd() dim val variant val = [stdev.s(if(not(isna(a1:a3)),a1:a3))] if iserror(val) sd = "---" else sd = val end if end function
Comments
Post a Comment