LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Combine two ranges with different numbers of rows and columns

Here is another macro for you to consider (less looping)...

Sub CombineRanges()
Dim X As Long, Rng1 As Range, Rng2 As Range, StartCell As Range
Set Rng1 = Range("Range1")
Set Rng2 = Range("Range2")
Set StartCell = Range("A1")
Rng2.Copy StartCell.Offset(, Rng1.Columns.Count).Resize( _
Rng1.Rows.Count * Rng2.Rows.Count, Rng2.Columns.Count)
For X = 1 To Rng2.Rows.Count * Rng2.Rows.Count
Rng1.Rows(X).Copy StartCell.Offset((X - 1) * _
Rng2.Rows.Count).Resize(Rng2.Rows.Count)
Next
End Sub

Like Jacob's macro, I'm assuming you named the two ranges that you want to
combine as indicated. Of course, you can set specific ranges, rather than
named ranges, in the two Set statements if desired.

--
Rick (MVP - Excel)


"Ciprian" wrote in message
...
Hi,

I have two different ranges with different numbers of rows and columns. I
have to combine in a single range each row from the first range with each
row
from the second range. I provide hereunder an example. Any idea? Thank
you!

Range 1
A B C
D E F
G H I
J K L

Range 2

1 2 3 4
5 6 7 8

Result

A B C 1 2 3 4
A B C 5 6 7 8
D E F 1 2 3 4
D E F 5 6 7 8
G H I 1 2 3 4
G H I 5 6 7 8
J K L 1 2 3 4
J K L 5 6 7 8



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not just remove dup rows but combine columns Colin Excel Worksheet Functions 1 January 14th 10 03:56 AM
need a macro to combine rows, columns mrsjcd3 Excel Programming 5 September 17th 09 01:44 PM
Combine multiple columns into two long columns, Repeating rows in first column [email protected] Excel Discussion (Misc queries) 2 July 31st 06 09:45 PM
Combine multiple columns into two long columns, Repeating rows in first column [email protected] Excel Discussion (Misc queries) 0 July 31st 06 05:07 PM
Combine 2 columns of numbers (A+B=C) Ledge Excel Programming 6 April 6th 06 10:24 AM


All times are GMT +1. The time now is 04:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"