Rows of data from columns - not simple transpose.

Jazzledizzle

New Member
Joined
Jul 20, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm sorry if I don't follow all of the rules as this is my first post, I may have missed some of them,

My current problem is I need to create one line of data from the table below, which contains a lot more data than just shown below, but as an example, I need to transform the data into one row, per unique lead reference. by example i'd need something like the row of data, from the table.

Output required:

LeadReferenceClientiD1ClientiD2ClientiD3ClientiD4ClientiD5ClientiD6ClientiD7ClientiD8ClientiD9ClientiD10ClientiD11Title1Title2Title3Title4Title5Title6Title7Title8Title9Title10Title11Forename1Forename2Forename3Forename4Forename5Forename6Forename7Forename8Forename9Forename10
90780390​
90780397​
90780390​
90780399​
90780391​
90780400​
90780392​
90780401​
90780394​
90780402​
90780396​
GroupGroupGroupGroupGroupGroupGroupGroupGroupGroup

Main table

Lead ReferenceCustomer ReferenceTitleForenameSurnameCompanyArea_desc2 1Row 1Start_seat 1No_seats 1Cost 1Ticket Net £VAT @ 20%GrossDining NetVAT @ 5%GrossTotalPrice_Band 1
90780390​
90780397​
GroupBT GroupM07
40​
162​
1​
8503​
1​
1​
2​
1​
1​
2​
0​
Arnold Hills EXEC
90780390​
90780390​
GroupBT GroupM07
39​
161​
1​
8503​
2​
2​
3​
2​
2​
3​
Arnold Hills EXEC
90780390​
90780399​
GroupBT GroupM07
40​
161​
1​
8503​
3​
3​
4​
3​
3​
4​
Arnold Hills EXEC
90780390​
90780391​
GroupBT GroupM07
39​
160​
1​
8503​
4​
4​
4​
4​
4​
5​
Arnold Hills EXEC
90780390​
90780400​
GroupBT GroupM07
40​
160​
1​
8503​
5​
5​
5​
5​
5​
6​
Arnold Hills EXEC
90780390​
90780392​
GroupBT GroupM07
39​
159​
1​
8503​
6​
6​
5.7​
6​
6​
7​
Arnold Hills EXEC
90780390​
90780401​
GroupBT GroupM07
40​
159​
1​
8503​
7​
7​
6.4​
7​
7​
8​
Arnold Hills EXEC
90780390​
90780394​
GroupBT GroupM07
39​
158​
1​
8503​
8​
8​
7.1​
8​
8​
9​
Arnold Hills EXEC
90780390​
90780402​
GroupBT GroupM07
40​
158​
1​
8503​
9​
9​
7.8​
9​
9​
10​
Arnold Hills EXEC
90780390​
90780396​
GroupBT GroupM07
39​
157​
1​
8503​
10​
10​
8.5​
10​
10​
11​
Arnold Hills EXEC
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Do you want to transpose only the Customer Reference? Do you want the result on a different sheet?
 
Upvote 0
I would love for every corresponding row that has the same unique Lead Reference to be put into a different sheet with just the unique lead reference.
 
Upvote 0
Try:
VBA Code:
Sub TransposeData()
    Application.ScreenUpdating = False
    Dim Rng As Range, RngList As Object, srcWS As Worksheet, desWS As Worksheet, key As Variant
    Dim rowCount As Long, LastRow As Long, lCol As Long, x As Long
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set RngList = CreateObject("Scripting.Dictionary")
    For Each Rng In srcWS.Range("A2", srcWS.Range("A" & srcWS.Rows.Count).End(xlUp))
        If Not RngList.Exists(Rng.Value) Then
            RngList.Add Rng.Value, Nothing
        End If
    Next
    For Each key In RngList
        With srcWS
            .Cells(1, 1).CurrentRegion.AutoFilter 1, key
            rowCount = .[subtotal(103,A:A)] - 1
            desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1) = key
            .Range("B2:B" & LastRow).SpecialCells(xlCellTypeVisible).Copy
            desWS.Cells(desWS.Rows.Count, "B").End(xlUp).Offset(1).PasteSpecial Transpose:=True
        End With
    Next key
    srcWS.Range("A1").AutoFilter
    With desWS
        lCol = .UsedRange.Columns.Count
        .Range("A1") = "Lead Reference"
        For x = 2 To lCol
            .Cells(1, x) = "ClientID" & x - 1
        Next x
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub TransposeData()
    Application.ScreenUpdating = False
    Dim Rng As Range, RngList As Object, srcWS As Worksheet, desWS As Worksheet, key As Variant
    Dim rowCount As Long, LastRow As Long, lCol As Long, x As Long
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set RngList = CreateObject("Scripting.Dictionary")
    For Each Rng In srcWS.Range("A2", srcWS.Range("A" & srcWS.Rows.Count).End(xlUp))
        If Not RngList.Exists(Rng.Value) Then
            RngList.Add Rng.Value, Nothing
        End If
    Next
    For Each key In RngList
        With srcWS
            .Cells(1, 1).CurrentRegion.AutoFilter 1, key
            rowCount = .[subtotal(103,A:A)] - 1
            desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1) = key
            .Range("B2:B" & LastRow).SpecialCells(xlCellTypeVisible).Copy
            desWS.Cells(desWS.Rows.Count, "B").End(xlUp).Offset(1).PasteSpecial Transpose:=True
        End With
    Next key
    srcWS.Range("A1").AutoFilter
    With desWS
        lCol = .UsedRange.Columns.Count
        .Range("A1") = "Lead Reference"
        For x = 2 To lCol
            .Cells(1, x) = "ClientID" & x - 1
        Next x
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
Thank you, is there a way to get the other columns to also be copied to sheet two in the same format?
 
Upvote 0
All in one row? Can you manually re-create Sheet2 to show what the result would look like and post a screen shot
 
Upvote 0
All in one row? Can you manually re-create Sheet2 to show what the result would look like and post a screen shot
Hey,

I put this in the question above, and in the interim, I'll try and recreate and screenshot.

Output required, but also including all columns into one row
LeadReferenceClientiD1ClientiD2ClientiD3ClientiD4ClientiD5ClientiD6ClientiD7ClientiD8ClientiD9ClientiD10ClientiD11Title1Title2Title3Title4Title5Title6Title7Title8Title9Title10Title11Forename1Forename2Forename3Forename4Forename5Forename6Forename7Forename8Forename9Forename10
9078039090780397907803909078039990780391907804009078039290780401907803949078040290780396GroupGroupGroupGroupGroupGroupGroupGroupGroupGroup
 
Upvote 0
Hey,

I put this in the question above, and in the interim, I'll try and recreate and screenshot.

Output required, but also including all columns into one row
LeadReferenceClientiD1ClientiD2ClientiD3ClientiD4ClientiD5ClientiD6ClientiD7ClientiD8ClientiD9ClientiD10ClientiD11Title1Title2Title3Title4Title5Title6Title7Title8Title9Title10Title11Forename1Forename2Forename3Forename4Forename5Forename6Forename7Forename8Forename9Forename10
9078039090780397907803909078039990780391907804009078039290780401907803949078040290780396GroupGroupGroupGroupGroupGroupGroupGroupGroupGroup
Something like the below, but including all the columns

Customer Reference1Customer Reference2Customer Reference3Customer Reference4Customer Reference5Customer Reference6Customer Reference7Customer Reference8Customer Reference9Customer Reference10Customer Reference11Title1Title2Title3Title4Title5Title6Title7Title8Title9Title10Forename1Forename2Forename3Forename4Forename5Forename6Forename7Forename8Forename9Forename10
x
90780397​
90780390​
90780399​
90780391​
90780400​
90780392​
90780401​
90780394​
90780402​
90780396​
 
Upvote 0
In the data you posted, the Title and Company columns are blank. Will there ever be any blanks in your actual data in any of the columns?
 
Upvote 0
In the data you posted, the Title and Company columns are blank. Will there ever be any blanks in your actual data in any of the columns?
Hi, yes there will be, but the empty spaces should be included in the output, as there will be more rows of data with different lead references so the titles will have to match the later rows data.

For example:
So the output will be two rows of data as there are two unique

Lead ReferenceCustomer ReferenceBlockRowSeatNo_seats 1Cost 1Ticket Net £VAT @ 20%GrossDining NetVAT @ 5%GrossTotalPrice_Band 1TitleForenameSurnameCompany
90801168​
90801167​
M05
35​
191​
1​
5508​
Arnold Hills EXECMrIanAgates
90801168​
90801168​
M05
35​
190​
1​
5508​
Arnold Hills EXECMrIanAgates
90054370​
90054370​
M07
34​
162​
1​
5008​
Arnold Hills EXECMrdurqanAneer
90054370​
90054369​
M07
34​
161​
1​
5008​
Arnold Hills EXECMrFurqanAnser
90054370​
90054372​
M07
34​
160​
1​
5008​
Arnold Hills EXECMrFqrqanAnder
90054370​
90054371​
M07
34​
159​
1​
5008​
Arnold Hills EXECMrFurqanAnwer
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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