Horizontal to Vertical

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
696
Office Version
  1. 2019
Platform
  1. Windows
NFL.xlsm
ABCDEFGHIJKLMNOP
1WeekWeekWeekweekHOUSEATENWeekJAXWASNEWeekMIACHILAR
21231KCATLDEN2TENARZSEA3JAXATLBUF
3HOUJAX
4KCTEN
5SEAWAS
6ATLARZ
7TENNE
8DENSEA
Sheet1


I'm looking to convert the Horizontal listing to Vertical, using a new column when "week" shows.
Vertical listing starts in Col A, then inserts a column to insert 2nd week (Col B), etc. 'insert' so it doesn't over-ride the original Horizontal listing (E:P).
 
You can try using Power Query.

Book1 (version 1).xlsb
ABCDEFGHIJKLMNOPQ
1Week1Week2Week3Week4Week5Week6Week7Week8Week9Week10Week11Week12Week13Week14Week15Week16Week17
2HOUCINMIADENTBKCNYGATLGBINDARZHOUDALNELACMINMIA
3KCCLEJAXNYJCHIBUFPHICARSFTENSEADETBALLAROAKNOBUF
4SEANYGCHIARZCARCINDETNEDENTBTENWASNODENBUFSFNO
5ATLCHIATLCARATLINDATLBUFATLCARBALDALATLCARDENARZCAR
6CLEATLLARINDCINDETPITTENSEAHOUDETBALDETHOUCARTBGB
7BALDALBUFCHIBALJAXBALCINBUFCLECARPITCHICHIGBDETCHI
8NYJDETWASJAXJAXATLNOOAKBALWASPHIOAKINDDALHOUMIABAL
9BUFGBCLECINHOUMINCARCLEINDDETCLEATLHOUCININDOAKCIN
10OAKMINTENCLEOAKWASCLEINDHOUJAXNELACCINGBNYJDENPIT
11CARINDMINDALKCNYGCINDETJAXGBHOUBUFMIADETLARLACCLE
12CHIBUFOAKNODENBALGBMINCARPHIGBNYGJAXTENDETCLEMIN
13DETMIANEDETNEPHIHOUGBKCNYGINDCINMINJAXTENNYJDET
14INDSFSFMINARZCLELACNYJDETCINPITTENOAKKCTBNYGTEN
15JAXNYJNYGHOUNYJPITMIAKCMINPITJAXINDNYJMIAATLBALHOU
16GBLARCINSEAPHIHOUCARLARCHIBUFATLCLEWASARZJAXCINJAX
17MINPHIPHIMIAPITTENNOMIATENARZNOJAXPITNYGBALHOUIND
18MIADENHOULACBUFMIABUFJAXNYGDENCINCARCLEMINNECHILAC
19NEPITPITTBTENDENNYJLACWASOAKWASMINTENTBMIAJAXKC
20PHICARNYJPITLARNYJDALNOOAKNYJLACARZLARINDCHIATLNYJ
21WASTBINDTENWASLACWASCHILACMIADENNEARZOAKMINKCNE
22LACJAXCARBALMIAGBSEASFMIASEADALMIANYGNYJCLEINDDAL
23CINTENLACWASSFTBARZSEAARZLARMINNYJSEASEANYGPITNYG
24TBWASDETNYGINDLARKCDALPITSFKCNOPHIATLSEACARWAS
25NOARZARZLARCLESFDENPHIDALNOOAKDENGBLACWASWASPHI
26ARZBALTBNENYGARZSFTBNOBALLARSFNENOPHILARATL
27SFHOUDENKCDALDALNENYGTBNETBLARLACPHIARZSEATB
28DALKCDALBUFMINTBNEMINKCDENWASKCPHIOAK
29LARLACSEAOAKSEAOAKNYJCHITBKCSFNODALDEN
30PITNEGBPHILACCHICHIBUFPITSFTENARZ
31NYGSEANOSFNOLARGBSFBUFDALGBLAR
32TENNOKCATLSEABALPITBUFSEA
33DENOAKBALGBPHICLECINNESF
Sheet11


Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
    Transpose0 = Table.Transpose(Source),
    WeekNum = Table.AddColumn(Transpose0, "Custom", each if [Column1] = "Week" then [Column1] & Text.From([Column2]) else null),
    FilledDown = Table.FillDown(WeekNum,{"Custom"}),
    FilteredRows = Table.SelectRows(FilledDown, each ([Column1] <> "Week")),
    UnpivotedColumns = Table.UnpivotOtherColumns(FilteredRows, {"Custom"}, "Attribute", "Value"),
    GroupedRows = Table.Group(UnpivotedColumns, {"Custom"}, {{"Count", each _, type table}}),
    Group = Table.TransformColumns(GroupedRows, {{"Count", each Text.Combine(_[Value],"-")}}),
    Split = Table.SplitColumn(Group, "Count", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Count.1", "Count.2", "Count.3", "Count.4", "Count.5", "Count.6", "Count.7", "Count.8", "Count.9", "Count.10", "Count.11", "Count.12", "Count.13", "Count.14", "Count.15", "Count.16", "Count.17", "Count.18", "Count.19", "Count.20", "Count.21", "Count.22", "Count.23", "Count.24", "Count.25", "Count.26", "Count.27", "Count.28", "Count.29", "Count.30", "Count.31", "Count.32"}),
    Transpose1 = Table.Transpose(Split),
    PromoteHeaders = Table.PromoteHeaders(Transpose1, [PromoteAllScalars=true])
in
    PromoteHeaders
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You can try using Power Query.

Book1 (version 1).xlsb
ABCDEFGHIJKLMNOPQ
1Week1Week2Week3Week4Week5Week6Week7Week8Week9Week10Week11Week12Week13Week14Week15Week16Week17
2HOUCINMIADENTBKCNYGATLGBINDARZHOUDALNELACMINMIA
3KCCLEJAXNYJCHIBUFPHICARSFTENSEADETBALLAROAKNOBUF
4SEANYGCHIARZCARCINDETNEDENTBTENWASNODENBUFSFNO
5ATLCHIATLCARATLINDATLBUFATLCARBALDALATLCARDENARZCAR
6CLEATLLARINDCINDETPITTENSEAHOUDETBALDETHOUCARTBGB
7BALDALBUFCHIBALJAXBALCINBUFCLECARPITCHICHIGBDETCHI
8NYJDETWASJAXJAXATLNOOAKBALWASPHIOAKINDDALHOUMIABAL
9BUFGBCLECINHOUMINCARCLEINDDETCLEATLHOUCININDOAKCIN
10OAKMINTENCLEOAKWASCLEINDHOUJAXNELACCINGBNYJDENPIT
11CARINDMINDALKCNYGCINDETJAXGBHOUBUFMIADETLARLACCLE
12CHIBUFOAKNODENBALGBMINCARPHIGBNYGJAXTENDETCLEMIN
13DETMIANEDETNEPHIHOUGBKCNYGINDCINMINJAXTENNYJDET
14INDSFSFMINARZCLELACNYJDETCINPITTENOAKKCTBNYGTEN
15JAXNYJNYGHOUNYJPITMIAKCMINPITJAXINDNYJMIAATLBALHOU
16GBLARCINSEAPHIHOUCARLARCHIBUFATLCLEWASARZJAXCINJAX
17MINPHIPHIMIAPITTENNOMIATENARZNOJAXPITNYGBALHOUIND
18MIADENHOULACBUFMIABUFJAXNYGDENCINCARCLEMINNECHILAC
19NEPITPITTBTENDENNYJLACWASOAKWASMINTENTBMIAJAXKC
20PHICARNYJPITLARNYJDALNOOAKNYJLACARZLARINDCHIATLNYJ
21WASTBINDTENWASLACWASCHILACMIADENNEARZOAKMINKCNE
22LACJAXCARBALMIAGBSEASFMIASEADALMIANYGNYJCLEINDDAL
23CINTENLACWASSFTBARZSEAARZLARMINNYJSEASEANYGPITNYG
24TBWASDETNYGINDLARKCDALPITSFKCNOPHIATLSEACARWAS
25NOARZARZLARCLESFDENPHIDALNOOAKDENGBLACWASWASPHI
26ARZBALTBNENYGARZSFTBNOBALLARSFNENOPHILARATL
27SFHOUDENKCDALDALNENYGTBNETBLARLACPHIARZSEATB
28DALKCDALBUFMINTBNEMINKCDENWASKCPHIOAK
29LARLACSEAOAKSEAOAKNYJCHITBKCSFNODALDEN
30PITNEGBPHILACCHICHIBUFPITSFTENARZ
31NYGSEANOSFNOLARGBSFBUFDALGBLAR
32TENNOKCATLSEABALPITBUFSEA
33DENOAKBALGBPHICLECINNESF
Sheet11


Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
    Transpose0 = Table.Transpose(Source),
    WeekNum = Table.AddColumn(Transpose0, "Custom", each if [Column1] = "Week" then [Column1] & Text.From([Column2]) else null),
    FilledDown = Table.FillDown(WeekNum,{"Custom"}),
    FilteredRows = Table.SelectRows(FilledDown, each ([Column1] <> "Week")),
    UnpivotedColumns = Table.UnpivotOtherColumns(FilteredRows, {"Custom"}, "Attribute", "Value"),
    GroupedRows = Table.Group(UnpivotedColumns, {"Custom"}, {{"Count", each _, type table}}),
    Group = Table.TransformColumns(GroupedRows, {{"Count", each Text.Combine(_[Value],"-")}}),
    Split = Table.SplitColumn(Group, "Count", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Count.1", "Count.2", "Count.3", "Count.4", "Count.5", "Count.6", "Count.7", "Count.8", "Count.9", "Count.10", "Count.11", "Count.12", "Count.13", "Count.14", "Count.15", "Count.16", "Count.17", "Count.18", "Count.19", "Count.20", "Count.21", "Count.22", "Count.23", "Count.24", "Count.25", "Count.26", "Count.27", "Count.28", "Count.29", "Count.30", "Count.31", "Count.32"}),
    Transpose1 = Table.Transpose(Split),
    PromoteHeaders = Table.PromoteHeaders(Transpose1, [PromoteAllScalars=true])
in
    PromoteHeaders
I've never used Power Query. I have it downloaded and installed.
What's the procedure and where do I put this code?
 
Upvote 0
Have you tried my suggestion in post#9?
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Another option
VBA Code:
Sub gtd()
   Dim Ary As Variant, Nary As Variant
   Dim c As Long, nr As Long, nc As Long
 
   Ary = Sheets("Raw").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To 34, 1 To UBound(Ary, 2))
 
   For c = 1 To UBound(Ary, 2)
      If LCase(Ary(1, c)) = "week" Then
         nr = 1: nc = nc + 1
      Else
         nr = nr + 2
      End If
      Nary(nr, nc) = Ary(1, c)
      Nary(nr + 1, nc) = Ary(2, c)
   Next c
   Sheets("Sheet1").Range("A1").Resize(UBound(Nary), nc).Value = Nary
End Sub
Hello,
I ran your macro successfully last time, but this time I get a "script out of range" error. Its right after the "End If" statement as noted below. When run line by line and it goes thru the error line many times, then I get the error. Any suggestions?

SQL:
Sub Horizontal_Vertical()

'NFL Horizontal to Vertical for Schedule
'using 'Raw'= original "Weeks"=Results
'from Fluff @ Mr Excel
'Horizontal to Vertical post
'format all as General or Text, Not Date


   Dim Ary As Variant, Nary As Variant
   Dim c As Long, nr As Long, nc As Long
  
   Ary = Sheets("Raw").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To 34, 1 To UBound(Ary, 2))
  
   For c = 1 To UBound(Ary, 2)
      If LCase(Ary(1, c)) = "week" Then 'what the entire cell is equal to
         nr = 1: nc = nc + 1
      Else
         nr = nr + 2
      End If
      Nary(nr, nc) = Ary(1, c) 'script out of range
      Nary(nr + 1, nc) = Ary(2, c)
   Next c
   Sheets("Weeks").Range("A1").Resize(UBound(Nary), nc).Value = Nary
  
End Sub

Here is the some of the data I'm using, the range ends at column "KI":
NFL.xlsm
ABCDEFGHIJKLMNOPQRSTUVW
1WEEKDALPHIPITNYJMINSFJAXSEAARZLACCLEMIAGBDENCHIBALWEEKNYGNOCINHOULAR
21TBATLBUFCARCINDETHOUINDTENWASKCNENONYGLARLVR2WASCARCHICLEIND
Raw
 
Last edited:
Upvote 0
Do you have any weeks with more than 16 Teams?
 
Upvote 0
Do you have any weeks with more than 16 Teams?
Yes. Some are labeled as TBA. I removed all the TBA's so its 16 or less, and the formula worked.
There are only 32 teams, so 16 would be the max number of games per week. I will make a note of "no more than 16".
Thank you.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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