excel - VBA concatenated arrays comparison - error 1004 coming up -
i have these entries in rows 1 10 , columns d:
a 10 10 b 20 b 20 c 30 c 30 d 40 d 40 e 50 e 50 f 60 f 60 g 70 h 80 90 j 100
with vba code (that paste below), wanting to, using vba arrays, build concatenated "virtual column" of , b , c , d. then, wanting create third array populated array gives me match result each array element using concatenation of , b compared same of c , d. (there's point this: it's prototype of more complex want build later on.)
it works until 6th element in array, beyond gives me 1004 error (with element values after empty in watch window).
can give me pointers why?
here (probably inelegant) vba code:
sub concatarray() dim count1 integer dim count2 integer count1 = application.counta(columns("a:a")) count2 = application.counta(columns("c:c")) dim column1() variant dim column2() variant dim virtcolumn3() variant dim column4() variant dim column5() variant dim virtcolumn6() variant redim virtcolumn3(1 count1, 1 1) redim virtcolumn6(1 count2, 1 1) column1 = range("a1:a" & count1) column2 = range("b1:b" & count1) column4 = range("e1:e" & count2) column5 = range("f1:f" & count2) = 1 count1 virtcolumn3(i, 1) = column1(i, 1) & column2(i, 1) next = 1 count2 virtcolumn6(i, 1) = column4(i, 1) & column5(i, 1) next dim virtcolumn7() variant redim virtcolumn7(1 count1, 1 1) = 1 count1 virtcolumn7(i, 1) = worksheetfunction.match(virtcolumn3(i, 1), virtcolumn6, 0) next end sub
it's snippet that's wrong:
= 1 count1 virtcolumn7(i, 1) = worksheetfunction.match(virtcolumn3(i, 1), virtcolumn6, 0) next
thanks in advance.
worksheetfunction.match()
throws error if match not found.
instead of trapping error, can use application.match()
version, returns error:
dim v 'variant = 1 count1 v = application.match(virtcolumn3(i, 1), virtcolumn6, 0) if not iserror(v) virtcolumn7(i, 1) = v next
Comments
Post a Comment