Excel Macro to Transpose the Data

Sivas

New Member
Joined
Aug 29, 2018
Messages
20
Hi, Can anyone help on the below macro code.

I have the data like below,

NameABC
ModelDEF
CityGHI
PlaceJKL
KM
ConditionMNO
1st Owner
2nd OwnerPQR
3rd Owner
PriceSTU
Delivered11111111
NameXYZ
ModelDJFHA
CitySAHJA
PlaceSHJ
KM
ConditionSAFH
1st Owner
2nd OwnerSAHJA
3rd OwnerFGH
PriceDJFHA
Delivered11111111

<tbody>
</tbody>

and the result should come as below,

NameModelCityPlaceKMCondition1st Owner2nd Owner3rd OwnerPriceDelivered
ABCDEFGHIJKL20MNOPQRSTU11111111
XYZDJFHASAHJASHJ5SAFHSAHJAFGHDJFHA11111111

<tbody>
</tbody>

I wrote a code as,

Sub Macro3()
'
' Macro3 Macro
' extraction
'
' Keyboard Shortcut: Ctrl+i
'
Range("B1:B11").Select
Selection.Copy
ActiveSheet.Next.Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
ActiveSheet.Previous.Select
Range("B13:B23").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True

It is taking only the particular range, but i have N number of data and it will get added more in future.

Can anyone help on this.

Thanks.
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this for results starting "D1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG27Feb04
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("A:A").SpecialCells(xlCellTypeConstants)
c = 1
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Areas
    c = c + 1
    [COLOR="Navy"]If[/COLOR] c = 2 [COLOR="Navy"]Then[/COLOR]
        Range("D1").Resize(, Dn.Count).Value = Application.Transpose(Dn.Value)
    [COLOR="Navy"]End[/COLOR] If
        Range("D" & c).Resize(, Dn.Count).Value = Application.Transpose(Dn.Offset(, 1).Value)
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you so much for your help Mick.

A small request. The report is generating in same sheet but I need the report in next sheet.

Can you please help.
 
Upvote 0
Putting results on next sheet :
Code:
Sub v()
Dim lr&, r&
lr = Cells(Rows.Count, "B").End(xlUp).Row
For r = 1 To lr Step 12
    Sheets(ActiveSheet.Index + 1).Cells(Rows.Count, "A").End(xlUp)(2).Resize(, 11) = _
        Application.Transpose(Cells(r, "B").Resize(11).Value)
Next
End Sub
 
Upvote 0
Thank you for your help.

The report is not getting generated properly, as per your code.

Can you please help me in getting it resolved
 
Upvote 0
In what way is it not producing what you need?
Are there always 11 rows in each data set with an empty row between each set?

If MickG's code does what you need try :
Code:
Sub MG27Feb04()
Dim Rng As range, Dn As range, c As Long
Set Rng = range("A:A").SpecialCells(xlCellTypeConstants)
c = 1
For Each Dn In Rng.Areas
    c = c + 1
    If c = 2 Then
        Sheets(ActiveSheet.Index + 1).range("A1").Resize(, Dn.Count).Value = Application.Transpose(Dn.Value)
    End If
        Sheets(ActiveSheet.Index + 1).range("A" & c).Resize(, Dn.Count).Value = Application.Transpose(Dn.Offset(, 1).Value)
Next Dn
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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