Transpose column to row

dgutu

New Member
Joined
Mar 12, 2013
Messages
2
[TABLE="width: 500"]
<tbody>[TR]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 192"]
<colgroup><col span="3"></colgroup><tbody>[TR]
[TD]QQ[/TD]
[TD]COL1[/TD]
[TD]COL2[/TD]
[/TR]
[TR]
[TD]q1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]45[/TD]
[/TR]
[TR]
[TD]q1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]45[/TD]
[/TR]
[TR]
[TD]q1[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]45[/TD]
[/TR]
[TR]
[TD]q1[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]4234[/TD]
[/TR]
[TR]
[TD]q2[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]q2[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]12[/TD]
[/TR]
[TR]
[TD]q2[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]q2[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]5[/TD]
[/TR]
</tbody>[/TABLE]

Hi I have the above table and I want obtain the following tables result. Please help.

[TABLE="class: outer_border, width: 256"]
<tbody>[TR]
[TD="width: 128, colspan: 2"]q1[/TD]
[TD="width: 128, colspan: 2"]q2
[/TD]
[/TR]
[TR]
[TD]col1[/TD]
[TD]col2[/TD]
[TD]col1[/TD]
[TD]col2[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]20[/TD]
[TD="align: right"]12[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]4234[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"]5[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range("E1") = "q1": Range("G1") = "q1"
Range("B1:C1").Copy Range("E2"): Range("B1:C1").Copy Range("G2")
drow1 = 3: drow2 = 3
For j = 2 To LR
  If Cells(j, 1) = "q1" Then
    Range("B" & j & ":C" & j).Copy Range("E" & drow1)
    drow1 = drow1 + 1
  End If
  If Cells(j, 1) = "q2" Then
    Range("B" & j & ":C" & j).Copy Range("G" & drow2)
    drow2 = drow2 + 1
  End If
Next
End Sub
 
Upvote 0
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range("E1") = "q1": Range("G1") = "q1"
Range("B1:C1").Copy Range("E2"): Range("B1:C1").Copy Range("G2")
drow1 = 3: drow2 = 3
For j = 2 To LR
  If Cells(j, 1) = "q1" Then
    Range("B" & j & ":C" & j).Copy Range("E" & drow1)
    drow1 = drow1 + 1
  End If
  If Cells(j, 1) = "q2" Then
    Range("B" & j & ":C" & j).Copy Range("G" & drow2)
    drow2 = drow2 + 1
  End If
Next
End Sub

thanks patel45
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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