Looking For Suggestions (Reformatting/ Transposing Data)

Starstick

New Member
Joined
May 29, 2017
Messages
1
Hi all,

I'm a bit of an excel newbie and am looking for suggestions for any functions/ scripts that will help with my reformatting problem!

I currently have a data set with three subheadings. (Number, Name and Fruit.) Currently each row represents a customer with an individual Number and Name who then have varying fruit values held on the same row. However, I now need to reformat the data so that the fruit values will now be held on separate rows per customer. (Example below.)

Currently:

NUMBERNAMEFRUITFRUITFRUIT
101NathanApplePear
102ChloePearPeach
103SteffanAppleBananaPear
104GlenBananaPear

<tbody>
</tbody>

End Goal:

NUMBERNAMEFRUIT
101NathanApple
101NathanPear
102ChloePear
102ChloePeach
103SteffanApple
103SteffanBanana
103SteffanPear
104GlenBanana
104GlenPear

<tbody>
</tbody>

I'm currently reviewing the data on a line by line basis and am creating new rows and transposing the data per customer but due to the multitude of data I'm looking for suggestions on if there is a better way to go about doing this as it's a little time consuming at the moment!

I'd appreciate any insight or suggestions that you could offer! Thank you in advance for any help. :)

Best wishes,
Starstick.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Starstick,

Welcome to MrExcel!!

Here's one way to do it:

Code:
Option Explicit
Sub Macro4()

    Dim lngLastRow  As Long
    Dim lngMyRow    As Long
    Dim lngPasteRow As Long
    Dim i As Integer
    
    Application.ScreenUpdating = False

    lngLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    For lngMyRow = lngLastRow To 2 Step -1 'Work backwards through the rows
        For i = 1 To Cells(lngMyRow, Columns.Count).End(xlToLeft).Column
            If i >= 4 Then 'Only copy and the clear data from Col. D on
                lngPasteRow = Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
                Cells(lngPasteRow, 1) = Cells(lngMyRow, 1)
                Cells(lngPasteRow, 2) = Cells(lngMyRow, 2)
                Cells(lngPasteRow, 3) = Cells(lngMyRow, i)
                Cells(lngMyRow, i).ClearContents
            End If
        Next i
    Next lngMyRow
    
    'Sort the dataset by Col. A (Number)
    lngLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range(Cells(2, "A"), Cells(lngLastRow, "C")).Sort Key1:=Range("A2"), Order1:=xlAscending, Orientation:=xlSortColumns, Header:=xlYes
    
    Application.ScreenUpdating = True
    
End Sub

Just initially run it on a copy of your data as the results cannot be undone if they're not as expected.

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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