multiple formulas?

danieley

New Member
Joined
May 26, 2011
Messages
9
Hi. I have employee ID numbers in Column A and data I need to pull in Column B. The same ID number may be listed in the first 3 rows and if so, I need the column B data in rows 2 and 3 to come up to new columns C and D respectively. I am new to the forum so I'm having trouble phrasing things. Here is what I have...

A1 12345 B1 Sam
A2 12345 B2 John
A3 12345 B3 Bill
A4 45678 B4 Jane
A5 45678 B5 Sally

Here is what I need...

A1 12345 B1 Sam C1 John D1 Bill
A4 45678 B1 Jane C1 Sally

There is no set pattern in the number of repeating ID numbers. Some are only listed once, some are listed ten times. Please let me know if you need further information. Formulas are better than macros for me if possible. Thanks.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Danieley,

Unfortunately, I don't know of a way to do what you want to only with formulas. Soon, I'll show a way using macros.

Important: make a copy of your list before try this code.

Try this (I use the example below):

1) Copy the code below.

Code:
Sub NamesData_v2()
'
'Prg    : NamesData_v2
'Author : Markmzz
'Date   : 25/05/2011
'Version: 02
'
    'Explicitly defines the variables
    Dim LastRowL1, LastRowL2, LastColL1, NextCol As Long
    Dim RL1, RL2, CL1, CL2, NCL1, NCL2, CCL2 As Long
    Dim NameList2 As String
 
    'Disable screen updating
    Application.ScreenUpdating = False
 
    'Determines the number of rows of the first list
    LastRowL1 = Cells(Rows.Count, 1).End(xlUp).Row
 
    'Determines the number of columns of the first list
    LastColL1 = Cells(1, Columns.Count).End(xlToLeft).Column
 
    'Determines the number of columns with
    'Name column out of the first list
    NCL1 = LastColL1 - 1
 
    'Sort, in ascending order, the 1st list
    Range(Cells(2, 1), Cells(LastRowL1, LastColL1)).Sort _
        Key1:=Range("A2"), _
        Order1:=xlAscending
 
    'Initial Column of the 2nd list
    NextCol = LastColL1 + 2
 
    'Create one sort list of unique names (list 2)
    Range(Cells(1, 1), Cells(LastRowL1, 1)).AdvancedFilter _
        Action:=xlFilterCopy, _
        CopyToRange:=Range(Cells(1, NextCol).Address), _
        Unique:=True
    Cells(1, NextCol).Font.Bold = False
 
    'Determines the number of rows from the second list
    LastRowL2 = Cells(Rows.Count, NextCol).End(xlUp).Row
 
    'Define two with the current Row in the 1st list
    RL1 = 2
 
    'Navigate by Names of the 2nd list
    For RL2 = 2 To LastRowL2
        'Show the progress in the Status Bar of the Excel
        Application.StatusBar = "Processing row " & RL2 & " of " & LastRowL2
        'Store the current Name of the 2nd list
        NameList2 = Cells(RL2, NextCol).Value
 
        'Define NextCol+1 with the current Column in the 2nd list
        CL2 = NextCol + 1
 
        'Navigate by Names in the 1st list that are equal
        'the current Name in the 2nd lists
        Do While Cells(RL1, 1) = NameList2
            'Fill, in the 2nd list, the data of the current name
            For CL1 = 2 To LastColL1
                Cells(RL2, CL2).Value = Cells(RL1, CL1).Value
                'Add one to the counter of the current Column in the 2st list
                CL2 = CL2 + 1
            Next CL1
            'Add one to the counter of the current Row in the 1st list
            RL1 = RL1 + 1
        Loop
    Next RL2
 
    'Determines the number of columns (Col2, Col3,...) in 2nd List
    NCL2 = (Cells(1, NextCol).CurrentRegion.Columns.Count - 1) / NCL1
 
    'Fill the labels of columns of 2nd List
    For CCL2 = 1 To NCL2
        For CL1 = 2 To LastColL1
            Cells(1, (CCL2 - 1) * NCL1 + NextCol + CL1 - 1).Value = _
                Cells(1, CL1).Value
        Next CL1
    Next CCL2
 
    'Autofit the columns of 2nd List
    Cells(1, NextCol).CurrentRegion.EntireColumn.AutoFit
 
    'Enable screen updating
    Application.ScreenUpdating = True
 
    'Reset the Status Bar of the Excel
    Application.StatusBar = False
End Sub

2) Give a right-click in the Worksheet Tab that contains the list and choose View Code.

3) In VBA window that appears, choose Module on the Insert menu of the respective window.

4) Now, paste the code copied in step 1) and close the VBA window.

5) Again on the worksheet that contains the list, activate the View tab, choose Macros in the Macros group.

6) In the Macro dialog box, select the name of the macro NamesData_v2 and click the Run button.

<TABLE style="BORDER-BOTTOM: #a6aab6 1px solid; BORDER-LEFT: #a6aab6 1px solid; BACKGROUND-COLOR: #ffffff; BORDER-COLLAPSE: collapse; BORDER-TOP: #a6aab6 1px solid; BORDER-RIGHT: #a6aab6 1px solid" rules=all cellPadding=2><COLGROUP><COL style="BACKGROUND-COLOR: #e0e0f0" width=25><COL><COL><COL><COL><COL><COL><COL></COLGROUP><THEAD><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #e0e0f0; COLOR: #161120"><TH></TH><TH>A</TH><TH>B</TH><TH>C</TH><TH>D</TH><TH>E</TH><TH>F</TH><TH>G</TH></TR></THEAD><TBODY><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">1</TD><TD style="FONT-WEIGHT: bold">ColID</TD><TD style="FONT-WEIGHT: bold">ColData</TD><TD style="TEXT-ALIGN: right"></TD><TD>ColID</TD><TD>ColData</TD><TD>ColData</TD><TD>ColData</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">2</TD><TD style="TEXT-ALIGN: right">12345</TD><TD>Sam</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right">12345</TD><TD>Sam</TD><TD>John</TD><TD>Bill</TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">3</TD><TD style="TEXT-ALIGN: right">12345</TD><TD>John</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right">45678</TD><TD>Jane</TD><TD>Sally</TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">4</TD><TD style="TEXT-ALIGN: right">12345</TD><TD>Bill</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">5</TD><TD style="TEXT-ALIGN: right">45678</TD><TD>Jane</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR><TR><TD style="TEXT-ALIGN: center; COLOR: #161120">6</TD><TD style="TEXT-ALIGN: right">45678</TD><TD>Sally</TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD><TD style="TEXT-ALIGN: right"></TD></TR></TBODY></TABLE>



Markmzz
 
Upvote 0
Markmzz, Thank you! I don't understand it but it appears to work...even for those with many repeats. Thanks for putting the time into this...I appreciate it very much.
 
Upvote 0
Markmzz, Thank you! I don't understand it but it appears to work...even for those with many repeats. Thanks for putting the time into this...I appreciate it very much.

Danieley,

I only tried to help you to resolve your problem.

Thanks for the feedback.

Markmzz
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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