excel vba - Macro populating dynamic array (from userform checkbox selections) -
i have array (i have 4 of these) populated based on user selecting between 1 , 4 checkboxes.
my question is: why can't populate array directly looping through checkboxes , finding selected ones?
this doesn't work:
dim chkbox control dim sectarr() variant dim s long s = 0 each chkbox in me.sectorsframe.controls 'sector-level frame if typename(chkbox) = "checkbox" , chkbox.value = true sectarr(s) = chkbox.caption s = s + 1 end if next
this works:
dim chkbox control dim sectarr variant, sectstr string sectstr = "" each chkbox in me.sectorsframe.controls 'sector-level frame if typename(chkbox) = "checkbox" , chkbox.value = true sectstr = sectstr & "|" & chkbox.caption end if next sectstr = right(sectstr, len(sectstr) - 1) sectarr = split(sectstr, "|")
i either "subscript out of range" (with parenthesis on array) or type mismatch (without parenthesis).
i'd not deal strings , chopping them , filling arrays them (do have deal them??). don't understand enough know can , can't do, though.
my next 3 arrays can have 1 - 6 options, , two-dimensional array multiple options possible.
=====================edit 2/3/2016 @ 1800z==========================
this looks promising - took said, petert, , played some, coming following (probably still clumsy) code:
dim chkbox control dim sectarr() variant dim sec long sec = 0 each chkbox in me.sectorsframe.controls 'sector-level frame if typename(chkbox) = "checkbox" , chkbox.value = true redim preserve sectarr(sec) sectarr(sec) = chkbox.caption sec = sec + 1 end if next
Comments
Post a Comment