Generating a list of random words in Excel, but no duplicates -
i'm trying generate words in column b list of given words in column a.
right code in excel vba this:
function gettext() dim givenwords givenwords = sheets(1).range(sheets(1).[a1], sheets(1).[a20]) gettext = a(application.randbetween(1, ubound(a)), 1) end function
this generates word list have provided in a1:a20
, i don't want duplicates.
gettext()
run 15 times in column b b1:b15
.
how can check duplicates in column b, or more efficiently, remove words temporarily list once has been used?
for example,
- select range
a1:a20
- select 1 value randomly (e.g
a5
) a5
in column b1- select range
a1:a4 , a6:a20
- select 1 value randomly (e.g
a7
) a7
in column b2- repeat, etc.
this trickier thought. formula should used vertical array eg. select cells want output, press f2 type =gettext(a1:a20) , press ctrl+shift+enter
this means can select input words in worksheet, , output can upto long list of inputs, @ point you'll start getting #n/a errors.
function gettext(givenwords range) dim item variant dim list new collection dim aoutput() variant dim tempindex integer dim x integer redim aoutput(givenwords.count - 1) variant each item in givenwords list.add (item.value) next x = 0 givenwords.count - 1 tempindex = int(rnd() * list.count + 1) aoutput(x) = list(tempindex) list.remove tempindex next gettext = application.worksheetfunction.transpose(aoutput()) end function
Comments
Post a Comment