Macro to Tranpose Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have data in Col F1 to M10 (max) that contains Data


I would like a macro or formula to transpose this data in Cell F15 Onwards

See Sample data below that needs to be transposed


Excel 2012
FGHIJKL
1KN-63301KN-63311KN-97260KN-97305KN-97290KN-97310KN-94300
2KN-63304KN-63314KN-97300KN-97325KN-97330
3KN-63303KN-63313KN-63314KN-63315
4
Sheet1
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi Rick

Thanks for the reply

I need a single row down from F15 onwards
 
Upvote 0
Hi Rick

Thanks for the reply

I need a single row down from F15 onwards
Okay, now, in what order? Using addresses only, which of these is the order for the transposing...
[TABLE="class: grid, width: 300, align: left"]
<tbody>[TR]
[TD="align: center"]F15[/TD]
[TD="align: center"]=>[/TD]
[TD="align: center"][/TD]
[TD="align: center"]F1[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]F1[/TD]
[/TR]
[TR]
[TD="align: center"]F16[/TD]
[TD="align: center"]=>[/TD]
[TD="align: center"][/TD]
[TD="align: center"]F2[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]G1[/TD]
[/TR]
[TR]
[TD="align: center"]F17[/TD]
[TD="align: center"]=>[/TD]
[TD="align: center"][/TD]
[TD="align: center"]F3[/TD]
[TD="align: center"][/TD]
[TD="align: center"]or[/TD]
[TD="align: center"][/TD]
[TD="align: center"]H1[/TD]
[/TR]
[TR]
[TD="align: center"]F18[/TD]
[TD="align: center"]=>[/TD]
[TD="align: center"][/TD]
[TD="align: center"]G1[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]I1[/TD]
[/TR]
[TR]
[TD="align: center"]etc.[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]etc.[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]etc.[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Thanks for the reply


The Data must be transposed from eg F1 to M1, then F2 to M2 etc in F15 , F16 onwards

See Sample data of data manually transposed



Excel 2012
F
14
15KN-63301
16KN-63311
17KN-97260
18KN-97305
19KN-97290
20KN-97310
21KN-94300
22KN-94301
23KN-63304
24KN-63314
25KN-97300
26KN-97325
27KN-97330
28KN-63303
29KN-63313
30KN-63314
31KN-63315
Sheet1
 
Upvote 0
The Data must be transposed from eg F1 to M1, then F2 to M2 etc in F15 , F16 onwards
Assuming your posted example data is representative of your actual data, give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub TransposeColumnsFthruM()
  Dim R As Long, C As Long, LastRow As Long, Joined As Variant
  Range("F15:F112").Clear
  LastRow = 14
  For R = 1 To Range("F1").CurrentRegion.Rows.Count
    Joined = Split(Trim(Join(Application.Index(Cells(R, "F").Resize(, 8).Value, 1, 0))))
    Cells(LastRow + 1, "F").Resize(UBound(Joined) + 1) = Application.Transpose(Joined)
    LastRow = LastRow + UBound(Joined) + 1
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hi Rick

I have run your code on another file & get type Mismatch and the following code is highlighted

Code:
 Cells(LastRow + 1, "F").Resize(UBound(Joined) + 1) = Application.Transpose(Joined)

Please test and advise


See Sample Data. Col E is data I inputted and Col F to M contains a Formula

Need to Transpose Data Col F1 to the last items row on Col M containing Data



Excel 2012
EFGHIJKLM
16721883216883218883200883202883208883210  
26983887400
36500A883003
46600M883104883105883114883115883004883005883014883015
Sheet1
Cell Formulas
RangeFormula
F1{=IF(COLUMNS($F1:F1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:F1))))}
G1{=IF(COLUMNS($F1:G1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:G1))))}
H1{=IF(COLUMNS($F1:H1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:H1))))}
I1{=IF(COLUMNS($F1:I1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:I1))))}
J1{=IF(COLUMNS($F1:J1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:J1))))}
K1{=IF(COLUMNS($F1:K1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:K1))))}
L1{=IF(COLUMNS($F1:L1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:L1))))}
M1{=IF(COLUMNS($F1:M1)>COUNTIF($A$1:$A$4000,$E1),"",INDEX($B$1:$B$4000,SMALL(IF($A$1:$A$4000=$E1,ROW($A$1:$A$4000)-ROW($A$1)+1),COLUMNS($F1:M1))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Since I don't have a data set for Columns A:B, I cannot produce the result set you have in the range F1:M4, so I made up a formula that fills in the data layout you show. No matter what I try, I cannot make my code fail... it works consistently for me. Can you post a copy of your workbook (sensitive data removed) to DropBox (or some other such file sharing service) so I can download it and watch my code fail... that would allow me to trace the problem directly.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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