Convert multiple rows of data to columns?

wolfgeek

New Member
Joined
Sep 1, 2011
Messages
1
I have a worksheet of customer information where each customer may have one or more rows. The data in each column is the same except for the last column (NOTES) is different. Here is an example:

Columns:
CustNum
Last
First
Notes

Rows:
1 Jones Fred Nice Guy
1 Jones Fred Pays on time
2 Smith Greg Net 90
2 Smith Greg Late 4 times
2 Smith Greg Boss's Brother-in-law

I need to convert this to one row per customer with each note in their own column. So the final result would look like this:

1 Jones Fred Nice Guy Pays on time
2 Smith Greg Net 90 Late 4 times Boss's Brother-in-law

I THINK I can do this with something like =if(a2=a3,d3,"") in column e, then =if(a2=a4,d4,"") in column f, etc. But since there can be anywhere between 1 and 6 rows per customer, I'm getting a bit confused.

Can anyone assist me on this. I'm open to learning new/better ways of doing this.

Thank you!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This quick little macro will do it.
Code:
Option Explicit

Sub MergeRows()
Dim LR As Long, Rw As Long
Dim delRNG As Range

LR = Range("A" & Rows.Count).End(xlUp).Row      'last row with data
Set delRNG = Range("A" & LR + 1)                'seed the delrng

For Rw = LR To 3 Step -1        'from the bottom up, merge
    If Range("A" & Rw) = Range("A" & Rw - 1) Then
        Range(Range("D" & Rw), Cells(Rw, Columns.Count).End(xlToLeft)).Copy _
            Cells(Rw - 1, Columns.Count).End(xlToLeft).Offset(, 1)
        Set delRNG = Union(delRNG, Range("A" & Rw))
    End If
Next Rw

If delRNG.Rows.Count > 1 Then delRNG.EntireRow.Delete xlShiftUp
Columns.AutoFit
End Sub


How/Where to install the macro:

1. Open up your workbook
2. Get into VB Editor (Press Alt+F11)
3. Insert a new module (Insert > Module)
4. Copy and Paste in your code (given above)
5. Get out of VBA (Press Alt+Q)
6. Save as a macro-enabled workbook

The macro is installed and ready to use. Press Alt-F8 and select MergeRows from the macro list.
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

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