LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,979
Default How to do a cartesian join in Excel?

You could create the list with programming. For example:

'==============================
Sub CopyCartersian()

Dim ws3 As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim lRow1 As Long
Dim lRow2 As Long
Dim lPaste As Long
Dim lCount As Long

Set ws3 = Worksheets("Sheet3")
Set rng1 = Worksheets("Sheet1").Range("A1").CurrentRegion
Set rng2 = Worksheets("Sheet2").Range("A1").CurrentRegion
lRow1 = rng1.Rows.Count
lRow2 = rng2.Rows.Count

For lCount = 1 To lRow2
lPaste = lRow1 * (lCount - 1) + 1
rng1.Copy Destination:=ws3.Cells(lPaste, 1)
With ws3
.Range(.Cells(lPaste, 2), .Cells(lPaste + lRow1 - 1, 2)) _
.Value = rng2.Cells(lCount).Value
End With
Next lCount

End Sub
'==========================

rkg wrote:
I have two worksheets, each having the primary key values stored in
column A. I want to create a new worksheet wherein each value in Column
A of worksheet 1 should join against each value in Column A of worksheet
2 and be stored in column A and B of the new worksheet.

Therefore, if Worksheet 1 and 2 look like:
Wk1-Col-A Wk2-Col-A
100 23
101 45
60
Wk3-Col-A-and-B should look like:
100 23
100 45
100 60
101 23
101 45
101 60

Any idea how to do this using macros or any other worksheet function?

Thanks so much for your help!




--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html

 
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
unhide menu bar in excel - just disappeared Sean Setting up and Configuration of Excel 12 April 4th 23 10:19 AM
Open Excel 2003 from Windows Explorer pmpjr Excel Discussion (Misc queries) 9 September 11th 06 03:58 PM
Using Excel 2000 VBA Application on Excel 2003 Excel Worksheet Functions 0 August 8th 06 02:36 AM
excel viewer littlebird0770 Setting up and Configuration of Excel 6 July 6th 06 04:10 PM
Excel file with hyperlinks takes a long time to open over the network Didier P Links and Linking in Excel 3 July 4th 06 04:39 PM


All times are GMT +1. The time now is 05:47 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"