Create multiple values based on two existing data sets.

Andy_Morland

New Member
Joined
Jan 27, 2015
Messages
5
Hi


So I currently have two sets of data, per below (unique ID and cost center).

Where I need to get to is to have a separate row of data for each unique ID and cost center (e.g. 4 unique ID's x 4 cost centers = 16 rows of data).

I feel like I'm missing something really simple here - and I don't think what I've put in the title describes what I'm after too well.


Thanks in advance!


[TABLE="class: grid, width: 426"]
<tbody>[TR]
[TD="align: center"]Unique ID[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Cost Center[/TD]
[TD="align: center"][/TD]
[TD="align: center"]Unique ID[/TD]
[TD="align: center"]Cost Center[/TD]
[/TR]
[TR]
[TD="align: center"]12345[/TD]
[TD="align: center"][/TD]
[TD="align: center"]98745617[/TD]
[TD="align: center"][/TD]
[TD="align: center"]12345[/TD]
[TD="align: center"]98745617[/TD]
[/TR]
[TR]
[TD="align: center"]67891[/TD]
[TD="align: center"][/TD]
[TD="align: center"]98756562[/TD]
[TD="align: center"][/TD]
[TD="align: center"]12345[/TD]
[TD="align: center"]98756562[/TD]
[/TR]
[TR]
[TD="align: center"]23456[/TD]
[TD="align: center"][/TD]
[TD="align: center"]98765632[/TD]
[TD="align: center"][/TD]
[TD="align: center"]12345[/TD]
[TD="align: center"]98765632[/TD]
[/TR]
[TR]
[TD="align: center"]78912[/TD]
[TD="align: center"][/TD]
[TD="align: center"]98786464[/TD]
[TD="align: center"][/TD]
[TD="align: center"]12345[/TD]
[TD="align: center"]98786464[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]67891[/TD]
[TD="align: center"]98745617[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]67891[/TD]
[TD="align: center"]98756562[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]67891[/TD]
[TD="align: center"]98765632[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]67891[/TD]
[TD="align: center"]98786464[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]23456[/TD]
[TD="align: center"]98745617[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]23456[/TD]
[TD="align: center"]98756562[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]23456[/TD]
[TD="align: center"]98765632[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]23456[/TD]
[TD="align: center"]98786464[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]78912[/TD]
[TD="align: center"]98745617[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]78912[/TD]
[TD="align: center"]98756562[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]78912[/TD]
[TD="align: center"]98765632[/TD]
[/TR]
[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]78912[/TD]
[TD="align: center"]98786464[/TD]
[/TR]
</tbody><colgroup><col><col><col><col><col><col></colgroup>[/TABLE]
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi ,

The list of unique IDs can be obtained by :

=INDEX(Unique_ID, INT((ROW(A1)-1)/ROWS(Cost_Center))+1)

Enter this in the first output row , and copy down.

The corresponding cost centers can be obtained by :

=INDEX(Cost_Center, MOD((ROW(A1)-1),ROWS(Cost_Center))+1)

Enter this in the first output row , and copy down.

Replace the names Unique_ID and Cost_Center with the absolute references for your data range.
 
Upvote 0
Andy,

If my above question is correct, this simple macro will output what you are looking for.

Code:
Sub Test()

    ActiveSheet.Range("C1").Value = "Unique ID"
    ActiveSheet.Range("D1").Value = "Cost Center"
    
    idLR = Range("A" & Rows.Count).End(xlUp).Row
    ccLR = Range("A" & Rows.Count).End(xlUp).Row
    
    Set idRng = ActiveSheet.Range("A2:A" & idLR)
    
    j = 2
    
    For Each cell In idRng
        For i = 2 To ccLR
            ActiveSheet.Range("C" & j).Value = cell.Value
            ActiveSheet.Range("D" & j).Value = ActiveSheet.Range("B" & i).Value
            j = j + 1
        Next i
    Next cell
    
End Sub

Let me know if you have any questions.

Bill
 
Upvote 0
Another option is
Code:
Sub CopyMultiple()

    Dim CcRws As Long
    Dim Cl As Range
    
    CcRws = Range("B" & Rows.Count).End(xlUp).Row - 1
    For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
        Range("C" & Rows.Count).End(xlUp).Offset(1).Resize(1 * CcRws) = Cl.Value
        Range("D" & Rows.Count).End(xlUp).Offset(1).Resize(CcRws).Value = Range("B2:B" & CcRws + 1).Value
    Next Cl

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,708
Messages
6,174,002
Members
452,542
Latest member
Bricklin

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