excel - how to change existed data in array vba -


in excel, have list of items weight. i've made function in vba picks random items out of list long total weight under 10.
before function made array of zero's should belong each item. when random function picks item, place in array should change one, part of function doesn't work.
can me solve problem/repair function?
code:

sub test()  dim weight single, totweight single dim finish boolean dim r integer const maxweight = 10  'here makes array of zero's dim arr(1 66) string, integer     r = 1 66          arr(r) = 0     next r  until finish = true       'pick random row out of excel sheet     r = int((65 * rnd()) + 2)      'the first titles (item, weight), that's why start row 2     if (totweight + cells(r, 2)) < maxweight         'sum picked weight total weight          totweight = totweight + cells(r, 2)           'change position of item in array 1         'but doesn't work -->      arr(r) = 1      else         'do long weight under 10         finish = true     end if loop  'it prints zero's  printarray arr, activeworkbook.worksheets("sheet1").[f1]  end sub  (btw, print function: sub printarray(data variant, cl range)     cl.resize(ubound(data, 1)) = data end sub)  

i debuged code, , seems problem in print function. try one

sub printarray(data variant, cl range)     dim integer     = lbound(data) ubound(data)         cl.cells(i, 1).value = data(i)     next end sub 

if interested why solution didnt work, think because tried assign array value. when need copy array, item item...


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -