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!


Unique IDCost CenterUnique IDCost Center
12345987456171234598745617
67891987565621234598756562
23456987656321234598765632
78912987864641234598786464
6789198745617
6789198756562
6789198765632
6789198786464
2345698745617
2345698756562
2345698765632
2345698786464
7891298745617
7891298756562
7891298765632
7891298786464

<tbody>
</tbody><colgroup><col><col><col><col><col><col></colgroup>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,215,363
Messages
6,124,505
Members
449,166
Latest member
hokjock

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