How can I combine data from multiple rows into one row?

k1njo

New Member
Joined
Sep 1, 2010
Messages
9
I have a spreadsheet where multiple entries are made for the same person, but on different rows. I'd like to somehow combine all data for a single person into one row. The first table is how it currently is. I'd like to create a formula to somehow combine all data for the rows with duplicate names. The second table is what I'm hoping it to look like.
Last NameFirst NameSunMonTueWedThuFriSat
SmithJohn1
SmithJohn1
AdamsKen1
SmithJohn1
AdamsKen1
AdamsKen1
SmithJohn1

<tbody>
</tbody>

Last NameFirst NameSunMonTueWedThuFriSat
AdamsKen111
SmithJohn1111

<tbody>
</tbody>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
k1njo,

Here is a macro solution for you to consider.

I assume that your raw data is in Sheet1, and, the results will be in Sheet2, and, that both worksheets already exist.

After testing the macro, if you want the results to replace the raw data, then I can re-write the macro.

Sample raw data (before, and, after the macro):


Excel 2007
ABCDEFGHIJ
1Last NameFirst NameSunMonTueWedThuFriSat
2SmithJohn1
3SmithJohn1
4AdamsKen1
5SmithJohn1
6AdamsKen1
7AdamsKen1
8SmithJohn1
9
Sheet1


And, after the macro in Sheet2:


Excel 2007
ABCDEFGHIJ
1Last NameFirst NameSunMonTueWedThuFriSat
2AdamsKen111
3SmithJohn1111
4
Sheet2


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub ReorgData()
' hiker95, 09/09/2016, ME963815
Dim oa As Variant
Dim a As Variant, i As Long, c As Long, lr As Long, lc As Long
Dim o As Variant, j As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")   '<-- you can change the sheet name here
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  oa = .Range(.Cells(1, 1), .Cells(lr, lc))
  .Range(.Cells(2, 1), .Cells(lr, lc)).Sort key1:=.Range("A2"), order1:=1, key2:=.Range("B2"), order2:=1
  a = .Range(.Cells(1, 1), .Cells(lr, lc))
  ReDim o(1 To UBound(a, 1), 1 To UBound(a, 2))
  .Range("A1").Resize(UBound(oa, 1), UBound(oa, 2)) = oa
End With
With CreateObject("Scripting.Dictionary")
  .CompareMode = vbTextCompare
  For i = 1 To UBound(a, 1)
    If Not .Exists(a(i, 1) & a(i, 2)) Then
      .Add a(i, 1) & a(i, 2), j
      j = j + 1
      For c = 1 To UBound(a, 2)
        If Not a(i, c) = vbEmpty Then
          o(j, c) = a(i, c)
        End If
      Next c
    Else
      For c = 3 To UBound(a, 2)
        If Not a(i, c) = vbEmpty Then
          o(j, c) = a(i, c)
        End If
      Next c
    End If
  Next i
End With
With Sheets("Sheet2")   '<-- you can change the sheet name here
  .UsedRange.ClearContents
  .Range("A1").Resize(UBound(o, 1), UBound(o, 2)) = o
  .Columns(1).Resize(, UBound(o, 2)).AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ReorgData macro.
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,126
Members
451,743
Latest member
matt3388

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