Transposing Info From Columns to Rows - Irregular Pattern

SimonHughes

Well-known Member
Joined
Sep 16, 2009
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a data set which is in column format and I need to transpose this to row format. There are four columns which could but will not always, have nil, 1, 2 3 or 4 entries and these need to be transposed in rows. The snip below shows original table and the desired outcome. Any help appreciated, many thanks.

Whitbread Remedials Temp.xlsx
BCDEFG
2Ref#LocationComment 1Comment 2Comment 3Comment 4
31ADRepair linkRemove port
42FD
53SWRepair linkClean duct
64ABClean ductReplace hatch
7
8
9Ref#LocationAction
101ADRepair link
111ADRemove port
123SWRepair link
133SWClean duct
144ABClean duct
155ABReplace hatch
Sheet2
 

Attachments

  • 1723187076331.png
    1723187076331.png
    12.9 KB · Views: 2
  • 1723187118427.png
    1723187118427.png
    12.9 KB · Views: 2
Two clicks in power query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    unPiv = Table.UnpivotOtherColumns(Source, {"Ref#", "Location"}, "Attribute", "Action"),
    delCol = Table.RemoveColumns(unPiv,{"Attribute"})
in
    delCol
Hi Jec, I do not know enough about Power Query to understand what I am supposed to do with your suggestion - I just do not know what the first step is but I am going to see what I can learn (I do know what it does and how to do basic things with PQ).
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here's a macro :
VBA Code:
Sub Transpose()

Dim Ws1 As Worksheet: Set Ws1 = Sheets("Sheet1") 'Change as required
Dim Ws2 As Worksheet: Set Ws2 = Sheets("Sheet2") 'Change as required
Dim P1 As Range: Set P1 = Ws1.UsedRange
Dim T1: T1 = P1
Dim T2()
Dim a%: a = 1
Dim i%, j%
ReDim Preserve T2(1 To 3, 1 To a)
T2(1, a) = "Ref#"
T2(2, a) = "Location"
T2(3, a) = "Action"
a = a + 1

For i = 2 To UBound(T1)
    For j = 3 To UBound(T1, 2)
        If T1(i, j) = "" Then GoTo n
        ReDim Preserve T2(1 To 3, 1 To a)
        T2(1, a) = T1(i, 1)
        T2(2, a) = T1(i, 2)
        T2(3, a) = T1(i, j)
        a = a + 1
n:  Next j
Next i

Ws2.[A1].Resize(UBound(T2, 2), UBound(T2)) = Application.Transpose(T2)
End Sub
Hi Footoo, I used this but it gave me very jumbled results. I will see what I can do with formula and PQ first but thanks you anyway.
 
Upvote 0
Can I upload a worksheet somehow?
Use XL2BB as you did in post #1 to give us small but representative samples of the various sheets/ranges & explain again in relation to the new sample data.
 
Upvote 0
this may help you with the PQ solution

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
this may help you with the PQ solution

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
Hi Alan, I am working my way through the PQ vids and have already sorted out how I can use it for the major work that I do - and it is fantastic so thanks for the steer. I am still working out how to transpose info with it but will plod on until I get it right. Again, thanks
 
Upvote 0
Load the table into PQ. Select the first two columns, right-click a header and choose 'Unpivot other columns'.
 
Upvote 0
Solution
Load the table into PQ. Select the first two columns, right-click a header and choose 'Unpivot other columns'.
Hi Rory, being looking and learning on Power Query and this method works a treat. PQ is going to be used a lot more in the future, many thanks.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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