Combined records from two sheets into a third

AndyCPF

New Member
Joined
Mar 16, 2010
Messages
9
Hi
I am looking for some assistance with what is hopefully a fairly simple macro or vba code
I have work book comprising of three sheets these are:
1. A list of customer codes
2. A list of product codes
3. A results sheet
The first sheet comprises of three columns
Customer code
Customer name
Customer discount
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
The second
Product code
Product name
Product price
<o:p></o:p>
What I am looking to do is to combine the two sheets into the third and to generate a product record for each customer
<o:p></o:p>
So for example if my customer sheet is
Cust Code<o:p></o:p>
Customer01
Customer02
Customer03
<o:p></o:p>
And my product sheet
Prod Code<o:p></o:p>
Product AA
Product AB
Product AC
<o:p></o:p>
I would like to produce a matrix of
Cust Code Prod Code<o:p></o:p>
Customer01 Product AA
Customer01 Product AB
Customer01 Product AC
Customer02 Product AA
Customer02 Product AB
Customer02 Product AC
Customer03 Product AA
Customer03 Product AB
Customer03 Product AC
<o:p></o:p>
Can anyone offer me some insight as to how I may achieve this?
<o:p></o:p>
Thanks in advance
Andy
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Does this help?

Code:
Sub AndyCPF()
Dim rcell As Range
Dim xcell As Range
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

For Each rcell In Sheets("Customer Code").Range("A2:A" & lr)

    For Each xcell In Sheets("Product Code").Range("A2:A" & lr)
    
        Sheets("Matrix").Range("A" & Rows.Count).End(3)(2).Value = rcell.Value
        Sheets("Matrix").Range("B" & Rows.Count).End(3)(2).Value = xcell.Value
        
    Next xcell
    
Next rcell


End Sub
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top