Summarizing Data from 2 columns into Rows

Jamzag

New Member
Joined
Dec 10, 2016
Messages
2
Hello All,

Newbie here so take it easy! :)

I have a lengthy list of data (~500 lines) that has 2 columns with where names appear multiple times if the person has more than one sector of access. I would like to segment my data into rows. See below for an example. Thanks in advance...

COLUMN ACOLUMN BCOLUMN CCOLUMN DCOLUMN ECOLUMN F
Existing Format
NameID#Access
John Smith3HQ
Jane Doe21HQ
Jane Doe21ISC
Jane Doe21Finance
Mike Thomas34Finance
Mike Thomas34ISC
John James7ISC
Sam Smith12Finance
Preferred Format
NameID#Access1Access2Access3Access4
John Smith3HQ
Jane Doe21HQISCFinance
Mike Thomas34FinanceISC
Sam Smith12Finance
John James7ISC

<tbody>
</tbody>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
7,493
Office Version
  1. 365
Platform
  1. Windows
Perhaps a Pivot Table.

vABCDEFGHIJK
1NameID#AccessCount of AccessAccess
2John Smith3HQNameID#FinanceHQISC
3Jane Doe21HQJane Doe
4Jane Doe21ISC21111
5Jane Doe21FinanceJohn James
6Mike Thomas34Finance71
7Mike Thomas34ISCJohn Smith
8John James7ISC31
9Sam Smith12FinanceMike Thomas
103411
11Sam Smith
12121
13
 
Upvote 0

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,075
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Welcome to the Forum!

Here's a macro that will rearrange your data, assumed to start with the header "Name" in cell A1, beginning in cell F1. The macro can easily be adapted if needed to insert rows for the rearranged data or place it somewhere else.

Code:
Sub jamzag()
Dim R As Range, V1 As Variant, Unq As Long, V2 As Variant, i As Long, j As Long, Vout As Variant, ct As Long
Set R = Range("A1").CurrentRegion
Application.ScreenUpdating = False
R.Columns(1).Resize(, 2).AdvancedFilter Action:=xlFilterCopy, copytorange:=[F1], unique:=True
Unq = Evaluate("SUMPRODUCT((" & R.Columns(3).Address(0, 0) & "<>"""")/COUNTIF(" _
    & R.Columns(3).Address(0, 0) & "," & R.Columns(3).Address(0, 0) & "&""""))") - 1
For i = 1 To Unq
    Range("H1").Resize(1, Unq)(i) = "Access" & i
Next i
Range("F1").Resize(1, Unq + 2).EntireColumn.AutoFit
Set R = R.Offset(1, 0).Resize(R.Rows.Count - 1)
V1 = R.Value
V2 = Range("F2:F" & Cells(Rows.Count, "F").End(xlUp).Row).Value
ReDim Vout(1 To UBound(V2), 1 To Unq)
For i = 1 To UBound(V2, 1)
    For j = 1 To UBound(V1, 1)
        If V1(j, 1) = V2(i, 1) Then
            ct = ct + 1
            Vout(i, ct) = V1(j, 3)
        End If
    Next j
    ct = 0
Next i
Range(Cells(2, "H"), Cells(UBound(V2, 1) + 1, 7 + Unq)).Value = Vout
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Here is my take on a macro to do what you want (output starts at cell F1)...
Code:
[table="width: 500"]
[tr]
	[td]Sub ChangeDataFormat()
  Dim R As Long, Z As Long, LastCol As Long, Data As Variant
  Data = Range("A2", Cells(Rows.Count, "C").End(xlUp))
  Columns("F:K").Clear
  With CreateObject("Scripting.Dictionary")
    For R = 1 To UBound(Data)
      If IsEmpty(.Item(Data(R, 1))) Then .Item(Data(R, 1)) = Data(R, 1) & vbTab & Data(R, 2)
      .Item(Data(R, 1)) = .Item(Data(R, 1)) & vbTab & Data(R, 3)
    Next
    Range("F2").Resize(.Count) = Application.Transpose(.Items)
  End With
  Range("F2").Resize(UBound(Data)).TextToColumns , xlDelimited, , , True, False, False, False, False
  LastCol = Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
  Range("F1:G1") = Array("Name", "ID#")
  Range("H1").Resize(, LastCol - 7) = Evaluate("""Access""&COLUMN(" & Range("A1").Resize(, LastCol - 7).Address & ")")
End Sub[/td]
[/tr]
[/table]

Note: The last three code lines are there strictly to place the headers for the output... if you already have headers pre-placed on row 1 starting at cell F1, then you can delete those last three code lines.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,686
Messages
5,988,068
Members
440,125
Latest member
vincentchu2369

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
Top