Swapping Rows & Colums

MrBez

New Member
Joined
Jul 24, 2014
Messages
2
Hi All,

Wondering if any of you out there could help with a problem I have in re-arranging some columns and rows. :confused:

Below is an example of the data as it is:

CustomerFRDFLTP DLG
A510 32
B102030 14

<tbody>
</tbody>


I am needing to have the data organised like:

CustomerProductAmount
AFR5
ADFL1
ATP0
ADLG32
BFR5
BDFL16
BTP20
BDLG19

<tbody>
</tbody>


Help !

Any solutions would be GREATLY appreciated :)
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Give this code a shot.

Note, you may need to change "Sheet1" and "Sheet2" (highlighted) to reflect the names of the worksheets in your workbook.

Code:
Public Sub TranspostList()
Dim i       As Long, _
    j       As Long, _
    sLR     As Long, _
    sLC     As Long, _
    dLR     As Long
    
Dim sWS     As Worksheet, _
    dWS     As Worksheet
    
Dim rCust   As String
    
With Application
    .ScreenUpdating = False
End With
    
Set sWS = Sheets([COLOR="#FF0000"]"Sheet1"[/COLOR])
Set dWS = Sheets([COLOR="#FF0000"]"Sheet2"[/COLOR])
    
sLR = Range("A" & Rows.Count).End(xlUp).Row
sLC = Cells(1, Columns.Count).End(xlToLeft).Column

dWS.Range("A1").Value = "Customer"
dWS.Range("B1").Value = "Product"
dWS.Range("C1").Value = "Amount"

For i = 2 To sLR
    rCust = sWS.Range("A" & i).Value
    dLR = dWS.Range("A" & Rows.Count).End(xlUp).Row + 1
    For j = 0 To sLC - 2
        dWS.Range("A" & dLR + j).Value = rCust
        dWS.Range("B" & dLR + j).Value = sWS.Cells(1, j + 2)
        dWS.Range("C" & dLR + j).Value = sWS.Cells(i, j + 2)
    Next j
Next i

With Application
    .ScreenUpdating = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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