VBA Help: Transpose data from duplicate rows to new columns

mganzlin

New Member
Joined
Nov 7, 2018
Messages
3
Hello! I have data that looks like this:
NameIDPositionSchoolEndorsement
Joe123
TeacherStellar ElementaryEndorsement 28
Joe123TeacherStellar ElementaryEndorsement 35
Joe123TeacherStellar ElementaryEndorsement 12
Jim124CustodianThunder MiddleEndorsement 25
Jim124CustodianThunder MiddleEndorsement 1
James125Teacher ElemLightning ElementaryEndorsement 15
Jill126TeacherNorth High SchoolEndorsement 28

<tbody>
</tbody>

And I want it to look like this:
NameIDPositionEndorsement 1Endorsement 2Endorsement 3
Joe123TeacherEndorsement 28Endorsement 35Endorsement 12
Jim124CustodianEndorsement 25Endorsement 1
James125Teacher ElemEndorsement 15
Jill126TeacherEndorsement 28

<tbody>
</tbody>

So there are no duplicate rows anymore. I need to keep the first 4 columns.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Welcome to the Board!

I just helped someone with a similar question just a few minutes ago. I minor adaption to that VBA should work for you, as long as your data is sorted like that so that records being grouped together are always lumped together.

Try this:
Code:
Sub MyCombineRows()


    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Set first row to start on (skipping first row of data)
    r = 3
    
    Do
'       Check to see if columns A, B, C, and D are equal to row above it
        If Cells(r, "A") = Cells(r - 1, "A") And Cells(r, "B") = Cells(r - 1, "B") And _
            Cells(r, "C") = Cells(r - 1, "C") And Cells(r, "D") = Cells(r - 1, "D") Then
'           Copy value from column E to end of row above it
            Cells(r - 1, Columns.Count).End(xlToLeft).Offset(0, 1) = Cells(r, "E")
'           Delete row
            Rows(r).Delete
        Else
'           Move on to next row
            r = r + 1
        End If
    Loop Until Cells(r, "A") = ""
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Ah, removed comments and it worked great. I'm literally crying happy tears. Thank you thank you thank you.
 
Upvote 0
You are welcome!

BTW, the comments shouldn't be an issue, as long as you left the single-quotes before them.
 
Upvote 0
Try this:

Thank you Joe4! Had a similar spreadsheet with multiple rows I needed to transpose to columns. Your comments on the VBA code really helped me to understand what I needed to do to modify it to get it done. THANK YOU SO MUCH!!
 
Upvote 0
Thank you Joe4! Had a similar spreadsheet with multiple rows I needed to transpose to columns. Your comments on the VBA code really helped me to understand what I needed to do to modify it to get it done. THANK YOU SO MUCH!!
You are welcome.
I am glad that the old thread helped you out!
And welcome to the Board!
:)
 
Upvote 0
Hi is it possible to also use this VBA code for multiple columns? where the code lists E to move data, I have 4 columns to move data up and to the end, is this possible?
 
Upvote 0
Hi is it possible to also use this VBA code for multiple columns? where the code lists E to move data, I have 4 columns to move data up and to the end, is this possible?
It should be possible, but I think it would be most helpful if you post a sample of your data and expected results, like the original poster did, so we can get a clear picture of exactly how your data is structured and your desired results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Also, while your question is somewhat similar to this, it is distinctly different. As such, it would probably be best to post it to a new thread (instead of posting it on to an old thread). That way, it will appear on the "Unanswered threads" listing for all to easily see, and will probably get more attention. You can always provide a link back to this thread in your new question, if you see a benefit in doing so.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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