simple excel code array issue -
so have 2 columns , b numbers in them, this.
a b 96.66666667 0 193.3333333 0 290 0 386.6666667 0 483.3333333 1 725 22 966.6666667 19 1208.333333 10 what want code @ column b , if value 0, put nothing in column c1. if column b >0, take corresponding value in a, , list value, b number of times. final goal column in c like:
483.3333333333333 725 725 725 725 etc til 725 happens 22 times 966 966 etc until 966 happens 19 times etc. any ideas?
as fast solution without later transposing use this:
sub test() dim values variant, counter variant values = [a1:a100].value 'change ranges fit needs counter = [b1:b100].value dim output() variant redim output(0 application.worksheetfunction.sum(counter) - 1, 0) dim long, j long while <= ubound(output) j = j + 1 = counter(j, 1) + - 1 output(i, 0) = values(j, 1) next wend [c1].resize(ubound(output) + 1).value = output 'change c1 cell start output end sub it generates array (output) pasted starting c1 (can changed)
Comments
Post a Comment