VBA Excel Return values from an array with loop -
i have small loop in vba function, gives me each month - i.e. parameter - respective contract list , works every month except december. contractlist vertical array (3,5,7,9,12). code:
k = 1 until month(parameter) < contractlist(k, 1) k = k + 1 loop nextcontract = monthname(contractlist(k, 1))
here problem: when month december, month(december) never smaller contractlist(k, 1) because 12 smallest value in array. in case, jump first value of array, i.e. "3". in other words, in last line nextcontract should monthname(contractlist(1, 1)). can give me hint how that?
thanks, appreciated!
there's sneaky way cheat uses mod
mod reduce value 0 when equals value looked (and multiples), can use month when december parameter zero, instead of 12...
do until (month(parameter) mod 12) < contractlist(k, 1)
this leave every other month alone, return 0 december.
Comments
Post a Comment