ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   union problem (https://www.excelbanter.com/excel-programming/322080-union-problem.html)

tom taol

union problem
 
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!

Tom Ogilvy

union problem
 
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

--
Regards,
Tom Ogilvy

"tom taol" wrote in message
...
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!




tom taol

union problem
 


thnak you, Tom
happy one to you

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


All times are GMT +1. The time now is 12:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com