Converting horizontal list to vertical - VBA

mhaidar81

New Member
Joined
Dec 9, 2017
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I am looking for a macro that would convert a horizontal list to a vertical one. All I can come up with is a macro to copy the row and paste it X number of times, but my list contains thousands of rows and doesn't seem very practical. Assuming ID column is column A:


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
A
---
ID[/TD]
[TD]
B
---
Project[/TD]
[TD]
C
---
Rate[/TD]
[TD="align: center"]D
---
Project A Count
[/TD]
[TD="align: center"]E
---
Project B Count
[/TD]
[TD="align: center"]F
---
Project C Count
[/TD]
[TD]
G
---

Total[/TD]
[TD]
H
---
Rate[/TD]
[TD="align: center"]I
---
Project D Count[/TD]
[TD="align: center"]J
---
Project E Count
[/TD]
[TD="align: center"]K
---
Project D Count
[/TD]
[TD]
L
---

Total[/TD]
[/TR]
[TR]
[TD="align: center"]1001[/TD]
[TD="align: center"]12001.01[/TD]
[TD="align: center"]$50[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]400[/TD]
[TD="align: center"]60[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]420[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Project[/TD]
[TD]Project Name[/TD]
[TD]Rate[/TD]
[TD]Count[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]1001[/TD]
[TD]Project A[/TD]
[TD]12001.01[/TD]
[TD]$50[/TD]
[TD]3[/TD]
[TD]150[/TD]
[/TR]
[TR]
[TD]1001[/TD]
[TD]Project B[/TD]
[TD]12001.01[/TD]
[TD]$50[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]1001[/TD]
[TD]Project C[/TD]
[TD]12001.01[/TD]
[TD]$50[/TD]
[TD]5[/TD]
[TD]250[/TD]
[/TR]
[TR]
[TD]1001[/TD]
[TD]Project D[/TD]
[TD]FR0006[/TD]
[TD]$60[/TD]
[TD]6[/TD]
[TD]360[/TD]
[/TR]
[TR]
[TD]1001[/TD]
[TD]Project E[/TD]
[TD]FR0003[/TD]
[TD]$60[/TD]
[TD]1[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD]1001[/TD]
[TD]Project F[/TD]
[TD]FR0005[/TD]
[TD]$60[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
</tbody>[/TABLE]

After the list is converted:


  • Project A, Project B, and Project C should always populate “Project Name” with the value from Column B
  • Project D should populate “Project Name” with the value “FR0006”
  • Project E should populate “Project Name” with the value “FR0003”
  • Project F should populate “Project Name” with the value “FR0005”

I would appreciate any help with this
 
Hey guys, I have a follow-up question on this. Let's say that there are additional columns within my sheet that contain useless information and I have no interest in converting them into the vertical format. Can I select the columns that I'm only interested in? The number of columns will be fixed in the sheet.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Never mind, I figured it out!

Hey guys, I have a follow-up question on this. Let's say that there are additional columns within my sheet that contain useless information and I have no interest in converting them into the vertical format. Can I select the columns that I'm only interested in? The number of columns will be fixed in the sheet.
 
Upvote 0
You can do that in my code by changing the below

Rich (BB code):
Set Rg = ActiveSheet.Range("A1").CurrentRegion '<--- Comment/delete this line

Set Rg = ActiveSheet.Range("A1", Range("L" & Rows.Count).End(xlUp))  '<--- Replace with this line

 
Upvote 0

Forum statistics

Threads
1,223,631
Messages
6,173,464
Members
452,516
Latest member
archcalx

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