Horizontal to Vertical Lines of Text

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
657
Office Version
  1. 2019
Platform
  1. Windows
I want to convert the horizontal line of text (L2:S3) to a vertical line of text (L) in pairs of 2, as shown below.

Horizontal to Verticle.jpg
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about:

VBA Code:
Sub Horizontal_Vertical()
  Dim c As Range, i As Long
  i = 5
  For Each c In Range("L2:S2")
    Range("L" & i).Resize(2).Value = Application.Transpose(Array(c, c.Offset(1)))
    i = i + 2
  Next
End Sub
 
Upvote 0
How about:

VBA Code:
Sub Horizontal_Vertical()
  Dim c As Range, i As Long
  i = 5
  For Each c In Range("L2:S2")
    Range("L" & i).Resize(2).Value = Application.Transpose(Array(c, c.Offset(1)))
    i = i + 2
  Next
End Sub
I had to adjust some ranges with your code, but works perfectly!!

thx for your reply.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0
Here is alternative means. Bring your data into Power Query. Unpivot your rows. Here is the Mcode
No VBA required or needed to learn to achieve this.

VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
    #"Sorted Rows" = Table.Sort(#"Unpivoted Columns",{{"Attribute", Order.Ascending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Attribute"})
in
    #"Removed Columns"

If you wish to learn more about PQ, then click on the link in my signature.
 
Upvote 0
And yet one more way... a loopless macro:
VBA Code:
Sub TransposeDoubleCellRange()
  Dim LastCol As String
  LastCol = Split(Cells(2, Columns.Count).End(xlToLeft).Address(, 0), "$")(0)
  Range("L5").Resize(2 * (Cells(1, LastCol).Column - 11)) = Application.Transpose(Split(Join(Evaluate(Replace("L2:@2&"" ""&L3:@3", "@", LastCol)))))
End Sub
Note: This macro assumes your data starts in cell L2. The 11 being subtracted is the number of the column immediately before the starting cell's column.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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