excel - Vb.net Custom sum formula not calculating when blank cell are present -
i have 2 problems 1 if have empty cells not work , second not calculate on tables when using sum column5 provided
the cinches converting string 12'-3 1/16" 147.0625 inches , tonearest16th converts string closest nearest sixteen of inch 12'-3 1/16" problem when trying sum results using conversion because if there blank cell error show me love guys again
public shared function totalsumtonearest(nums object) object '---------------------------------------------------------------------- '** demonstrates how use array(or range of multiple cells) ' function argument. ' can called formulas such =getarray(a1:b5), getarray(a1), ' or getarray({1,2,3;4,5,6}). '---------------------------------------------------------------------- dim sum double, v object on error goto handler if isarray(nums) each v in nums 'if typeof v.getvalue() excelempty 'else sum = sum + cdbl(cinches(v) / 12) 'end if next else sum = cdbl(nums) end if totalsumtonearest = tonearest16th(sum * 12) exit function handler: ' getarray = cverr(2036) 'xlerrnum = 2036 end function
i'm posting working code in case can use it
public shared function sum_tonearest_16th(values object) object '---------------------------------------------------------------------- '** demonstrates how use array(or range of multiple cells) ' function argument. ' can called formulas such =getarray(a1:b5), getarray(a1), ' or getarray({1,2,3;4,5,6}). '---------------------------------------------------------------------- dim sum double if isarray(values) each objectvalue object in values dim doublevalue double = 0 if typeof objectvalue string ' dim rst string="" doublevalue = cdbl(cinches(objectvalue)) ' objectvalue=rst elseif typeof objectvalue double doublevalue = objectvalue else double.tryparse(objectvalue.tostring(), doublevalue) end if sum += doublevalue next objectvalue else double.tryparse(values.tostring(), sum) end if return to_nearest_16th(sum) end function
Comments
Post a Comment