union problem

T

tom taol

the below source have problem.
i wanna be value of a11 ~ c12, as follow.
a11=2,b11=5,c11=9,a12=4,b12=7,c12=8

Sub rng_unio_ex()
Dim rng_source As Range, rng_source2 As Range
Set rng_source = Range("a7:c7")'a7=2,b7=5,c7=9
Set rng_source2 = Range("b9:d9")'b9=4,c9=7,d9=8

ReDim arry(1 To 2, 1 To 3) As Range

Set rng_unio = Union(rng_source, rng_source2)
For i = 1 To 2
For k = 1 To 3
m = m + 1
Set arry(i, k) = rng_unio(m)
Next
Next
Range("a11:c12").Value = arry
End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

Tom Ogilvy

Certainly not a generalized solution, but this works:

Sub rng_unio_ex()
Dim rng_source As Range, rng_source2 As Range
Set rng_source = Range("a7:c7") 'a7=2,b7=5,c7=9
Set rng_source2 = Range("b9:d9") 'b9=4,c9=7,d9=8

ReDim arry(1 To 2, 1 To 3) As Range

Set rng_unio = Union(rng_source, rng_source2)
For i = 1 To 2
m = 0
For k = 1 To 3
m = m + 1
Set arry(i, k) = rng_unio.Areas(i)(m)
Next
Next
Range("a11:c12").Value = arry
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top