Monday, 15 April 2013

excel - Looping through 8204 variable type (array of variants) -



excel - Looping through 8204 variable type (array of variants) -

i'm having problem looping through variant array (8204 variable type). i'm seeking input via input box (type 8) , user able ctrl+ multiple disjointed ranges , cells. problem running when seek , loop through selected ranges picks first one.

here's working illustration of issue:

sub myarray() myanswer = application.inputbox("pick description cell(s) in spreadsheet link" _ & vbnewline & "(hold ctrl select multiple cells)", type:=8) ' if type 8204 if vartype(myanswer) = 8204 msgbox "length of array: " & ubound(myanswer) ' loop through each element in array each vvalue in myanswer msgbox vvalue next end if end sub

in prompt type next or select ranges using ctrl+:

$a$12:$a$13,$b$4:$c$4,$d$4

for reason can pick first range $a$12:$a$13 when loop through elements in ranges/cells.

any help much appreciated. thanks!

application.inputbox returns range object, because not using set uses default property .value, returns values of first area.

sub myarray() dim myanswer range set myanswer = application.inputbox("pick description cell(s) in spreadsheet link" _ & vbnewline & "(hold ctrl select multiple cells)", type:=8) ' if type 8204 if not myanswer nil dim cell range ' loop through each cell in range each cell in myanswer msgbox cell.value next end if end sub

excel vba excel-vba

No comments:

Post a Comment