Transpose date from rows to columns for multiple rows using macro

KD23

New Member
Joined
Jan 26, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a set of data i need to transpose hopefully with the use of a macro if possibly. Any other way would be helpful too but I dont really see how to get this done.

This is what my data looks like:
Knipsel.PNG


And this is what I want it to look like after:
Knipsel2.PNG


Hopefully someone can help me.

Thank you
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Welcome to MrExcel Message Board.
You can do it with formula.
Select the exact range at source with rows (same as source colummns) and Reverse.
if your source has 5 rows and 3 columns, you should select 3 rows & 5 columns then Input (change to your Source or Select it):
Excel Formula:
=TRANSPOSE(B4:D21)
and Press CTRL+SHift+ENTER

Book1
ABCDEFGHIJKLMNO
1
2123456789
335791113151719
41344812162024283236
5258
63712
74916
851120
961324
1071528
1181732
1291936
13
Sheet1
Cell Formulas
RangeFormula
F2:N4F2=TRANSPOSE(B4:D12)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Welcome to MrExcel Message Board.
You can do it with formula.
Select the exact range at source with rows (same as source colummns) and Reverse.
if your source has 5 rows and 3 columns, you should select 3 rows & 5 columns then Input (change to your Source or Select it):
Excel Formula:
=TRANSPOSE(B4:D21)
and Press CTRL+SHift+ENTER

Book1
ABCDEFGHIJKLMNO
1
2123456789
335791113151719
41344812162024283236
5258
63712
74916
851120
961324
1071528
1181732
1291936
13
Sheet1
Cell Formulas
RangeFormula
F2:N4F2=TRANSPOSE(B4:D12)
Press CTRL+SHIFT+ENTER to enter array formulas.
Thank you for your response, but as you can see in my example, there are a few things that do not need to be transposed, so this method does not work.
 
Upvote 0
Try this Macro:
VBA Code:
Sub TransformData()
Dim i As Long, Lr As Long, j As Long, Cell As Range, Lc As Long, L As Long, K1 As Long
Dim Lr2 As Long
Lr = Range("A" & Rows.Count).End(xlUp).Row
Lc = Cells(2, Columns.Count).End(xlToLeft).Column
Range("B" & Lr + 2).Value = "Project Type"
Range("C" & Lr + 2).Value = "Project #"
Range("D" & Lr + 2).Value = "Project Name"
Range("E" & Lr + 2).Value = "Date"
Range("F" & Lr + 2).Value = "Amount"
Lr2 = Lr + 3
For i = 3 To Lr
L = 0
K1 = Application.WorksheetFunction.Count(Range(Cells(i, 5), Cells(i, Lc))) - 1
Range("B" & Lr2 & ":B" & Lr2 + K1).Value = Range("C" & i).Value
Range("C" & Lr2 & ":C" & Lr2 + K1).Value = Range("B" & i).Value
Range("D" & Lr2 & ":D" & Lr2 + K1).Value = Range("A" & i).Value
For j = 5 To Lc
If Cells(i, j).Value = "" Then
Else
Range("E" & Lr2 + L).Value = Cells(2, j).Value
Range("F" & Lr2 + L).Value = Cells(i, j).Value
L = L + 1
End If
Next j
Lr2 = Range("B" & Rows.Count).End(xlUp).Row + 1
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,694
Members
449,117
Latest member
Aaagu

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