Transpose Columns To Rows base on a few fields.

walkes

New Member
Joined
Jan 29, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have source file like this:
JanuaryFebruaryMarzec
uuidNameLast nameSUMABCDESUMABCDESUMABCDE
1​
JohnDoe
709​
709​
0​
450​
200​
250​
2​
JaneDoe
1 120​
500​
620​
400​
400​
0​


And I need output file like this:

uuidNameLast nameMonthTypeValue
1​
JohnDoeJanuaryC
709​
2​
JaneDoeJanuaryA
500​
2​
JaneDoeJanuaryC
620​
2​
JaneDoeFebruaryA
400​
1​
JohnDoeMarchB
200​
1​
JaneDoeMarchD
250​

I found how to make Transpose, but I need way how to copy only lines with values taking names and drop SUM.

Sub TransposeInsertRows()
Dim xRg As Range
Dim i As Long, j As Long, k As Long
Dim x As Long, y As Long
Set xRg = Application.InputBox _
(Prompt:="Range Selection...", _
Title:="Range", Type:=8)
Application.ScreenUpdating = False
x = xRg(1, 1).Column + 1
y = xRg(1, xRg.Columns.Count).Column
For i = xRg(xRg.Rows.Count, 1).Row To xRg(1, 1).Row Step -1
If Cells(i, x) <> "" And Cells(i, x + 1) <> "" Then
k = Cells(i, x - 1).End(xlToRight).Column
If k > y Then k = y
For j = k To x + 1 Step -1
Cells(i + 1, 1).EntireRow.Insert
With Cells(i + 1, x - 1)
.Value = .Offset(-1, 0)
.Offset(0, 1) = .Offset(-1, 1)
.Offset(0, 1) = Cells(i, j)
End With
Cells(i, j).ClearContents
Next j
End If
Next i
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
OMG! Stop with the VBA! Learn Power Query. This problem is a bit difficult (made more difficult by not using XL2BB), but is EXACTLY what Power Query does best! Great playlists on it here and here.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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