Macro for transposing Column to muliple rows

ann19san

New Member
Joined
Dec 12, 2017
Messages
4
Can someone help me help me how to create a macro that would transpose the following amount in column to rows that match the dates, here is an example:
Raw data from sheet 1:
DateAmount
Oct 14, 20171
Oct 21, 20172
Oct 28, 20173
Nov 4, 20174
Nov 11, 20175
Nov 18, 20176
Nov 25, 20177
Dec 2, 20178
Dec 9, 20179
Dec 16, 201710
Dec 23, 201711
Dec 30, 201712
Jan 6, 201813
Jan 13, 201814
Oct 14, 201715
Oct 21, 201716
Oct 28, 201717
Nov 4, 201718
Nov 11, 201719
Nov 18, 201720
Nov 25, 201721
Dec 2, 201722
Dec 9, 201723
Dec 16, 201724
Dec 23, 201725
Dec 30, 201726
Jan 6, 201827
Jan 13, 201828
Oct 14, 201729
Oct 21, 201730
Oct 28, 201731
Nov 4, 201732
Nov 11, 201733
Nov 18, 201734
Nov 25, 201735
Dec 2, 201736
Dec 9, 201737
Dec 16, 201738
Dec 23, 201739
Dec 30, 201740
Jan 6, 201841
Jan 13, 201842

<colgroup><col><col></colgroup><tbody>
</tbody>

Result in Sheet 2:
Oct 14, 2017Oct 21, 2017Oct 28, 2017Nov 4, 2017Nov 11, 2017Nov 18, 2017Nov 25, 2017Dec 2, 2017Dec 9, 2017Dec 16, 2017Dec 23, 2017Dec 30, 2017Jan 6, 2018Jan 13, 2018
1234567891011121314
1516171819202122232425262728
2930313233343536373839404142

<colgroup><col span="3"><col><col span="3"><col span="2"><col span="3"><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hello,

In your Sheet 2 cell A1, you can have :

Code:
=OFFSET(Sheet1!$A$2,((ROW()-1)*14)+COLUMN()-1,0)

To be copied for the whole of Row 1

AND in your Sheet 2 cell A2, you can have :

Code:
=OFFSET(Sheet1!$A$2,((ROW()-2)*14)+COLUMN()-1,1)

To be copied for the whole Sheet 2 ...

Hope this will help
 
Upvote 0
Can someone help me help me how to create a macro that would transpose the following amount in column to rows that match the dates, here is an example:
Raw data from sheet 1:
DateAmount
Oct 14, 20171
Oct 21, 20172
Oct 28, 20173
Nov 4, 20174
Nov 11, 20175
Nov 18, 20176
Nov 25, 20177
Dec 2, 20178
Dec 9, 20179
Dec 16, 201710
Dec 23, 201711
Dec 30, 201712
Jan 6, 201813
Jan 13, 201814
Oct 14, 201715
Oct 21, 201716
Oct 28, 201717
Nov 4, 201718
Nov 11, 201719
Nov 18, 201720
Nov 25, 201721
Dec 2, 201722
Dec 9, 201723
Dec 16, 201724
Dec 23, 201725
Dec 30, 201726
Jan 6, 201827
Jan 13, 201828
Oct 14, 201729
Oct 21, 201730
Oct 28, 201731
Nov 4, 201732
Nov 11, 201733
Nov 18, 201734
Nov 25, 201735
Dec 2, 201736
Dec 9, 201737
Dec 16, 201738
Dec 23, 201739
Dec 30, 201740
Jan 6, 201841
Jan 13, 201842

<tbody>
</tbody>

Result in Sheet 2:
Oct 14, 2017Oct 21, 2017Oct 28, 2017Nov 4, 2017Nov 11, 2017Nov 18, 2017Nov 25, 2017Dec 2, 2017Dec 9, 2017Dec 16, 2017Dec 23, 2017Dec 30, 2017Jan 6, 2018Jan 13, 2018
1234567891011121314
1516171819202122232425262728
2930313233343536373839404142

<tbody>
</tbody>

Hi,
Open new workbook and add sheet2 and use below code.


Sub TestUnique()
Dim Sh As Worksheet
Dim Dsh As Worksheet
Dim Cel As Range, Celadr As String
Dim i As Long
Dim Kt As Long


With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
Set Sh = ThisWorkbook.Worksheets("Sheet1")
Set Dsh = ThisWorkbook.Worksheets("Sheet2")
Dsh.Cells.ClearContents
Sh.Range("A2:A" & Sh.Cells(Rows.Count, 1).End(xlUp).Row).Copy Destination:=Sh.Range("h1")
Sh.Range("h1:h" & Sh.Cells(Rows.Count, 1).End(xlUp).Row).RemoveDuplicates Columns:=1, Header:=xlNo
Sh.Range("h1:h" & Sh.Cells(Rows.Count, 1).End(xlUp).Row).Copy
Dsh.Range("a1").PasteSpecial (xlPasteValues), Transpose:=True
Application.CutCopyMode = False
Sh.Range("h1").EntireColumn.ClearContents
For i = 1 To Dsh.Cells(1, Columns.Count).End(xlToLeft).Column
Set Cel = Sh.Cells.Find(Dsh.Cells(1, i))
Celadr = Cel.Address
If Not Cel Is Nothing Then
Do
Kt = Dsh.Cells(Rows.Count, i).End(xlUp).Row + 1
Dsh.Cells(Kt, i) = Cel.Offset(0, 1)
Set Cel = Sh.Cells.FindNext(Cel)
Loop While Not Cel Is Nothing And Cel.Address <> Celadr
End If


Next i






End Sub
 
Upvote 0
If you're still interested in a macro, how about
Code:
Sub CopyTransposeMultiRows()

   Dim Cl As Range
   Dim itm As Variant
   Dim Col As Long
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Cl.Offset(, 1).Value
         Else
            .Item(Cl.Value) = .Item(Cl.Value) & "," & Cl.Offset(, 1).Value
         End If
      Next Cl
      Col = 1
      Sheets("Sheet2").Range("A1").Resize(, .Count).Value = .keys
      For Each itm In .items
         Sheets("Sheet2").Cells(2, Col).Resize(UBound(Split(itm, ",")) + 1) = Application.Transpose(Split(itm, ","))
         Col = Col + 1
      Next itm
   End With
End Sub
 
Upvote 0
If you're still interested in a macro, how about
Code:
Sub CopyTransposeMultiRows()

   Dim Cl As Range
   Dim itm As Variant
   Dim Col As Long
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Cl.Offset(, 1).Value
         Else
            .Item(Cl.Value) = .Item(Cl.Value) & "," & Cl.Offset(, 1).Value
         End If
      Next Cl
      Col = 1
      Sheets("Sheet2").Range("A1").Resize(, .Count).Value = .keys
      For Each itm In .items
         Sheets("Sheet2").Cells(2, Col).Resize(UBound(Split(itm, ",")) + 1) = Application.Transpose(Split(itm, ","))
         Col = Col + 1
      Next itm
   End With
End Sub


Very Concise Code Nice Fluff ..
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
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