excel - List occupied cells across multiple cells -
i have 4 variables , wish list (maximum of 3) variables being used. have used vba functions before stumped reason isn't working..
the 4 variables percentages example:
if (20%,empty,20%,60%) want 3 cells (a,c,d)
if (50%,50%,empty,empty) => (a,b,empty)
hello,
if (empty,empty,100%,empty) => (c,empty,empty)
the code have @ moment isn't working (for first cell):
function whichtoa(w integer, x integer, y integer, z integer) string if w <> 0 whichtoa = "a" elseif x <> 0 whichtoa = "b" elseif y <> 0 whichtoa = "c" elseif z <> 0 whichtoa = "d" end if end function could empty cells being general , others being percentage? can't change data coming program. use null check or similar?
thanks in advance!
lucas
consider following data. last column has formula whichtoa
a b c d e 60% 40% 30% 30% abc 30% 60% 30% 90% abc 10% 20% 50% abc 30% 50% bc 30% c 50% 60% cd if using percentages need use other integer in function since you're dealing decimals.
function whichtoa(w double, x double, y double, z double) string dim emptycount integer dim results string ' assume 0 valuecount = 0 ' assume empty string results = "" if w <> 0 results = results & "a" valuecount = valuecount + 1 end if if x <> 0 results = results & "b" valuecount = valuecount + 1 end if if y <> 0 results = results & "c" valuecount = valuecount + 1 end if ' time need check condition of valuecount. if want 3 maximum if (z <> 0) , (valuecount < 3) results = results & "d" end if whichtoa = results end function each condition checked individually. if block have process first match , stop evaluating block. then, counting number of positive values, or hits if will, valuecount can stop processing if 3 hits. needs checked z parameter in event have 3 hits @ point. build results string , return it.
Comments
Post a Comment