Columns to Rows using Excel Formula

pto160

Active Member
Joined
Feb 1, 2009
Messages
478
Office Version
  1. 365
Platform
  1. Windows
I would like to convert data from columns to rows. I already got a VBA solution for it. Is there an Excel formula solution? Here is the data.

Book2
ABCDEFG
1Jan SalesFeb SalesMar SalesApril SalesMay SalesJune Sales
2Item A1589
3Item B100102108456
4Item c1000789
5
6Expected Results
7Item AFeb Sales15
8Item AJune Sales89
9Item BJan Sales100
10Item BMar Sales102
11Item BApril Sales108
12Item BJune Sales456
13Item cMar Sales1000
14Item cMay Sales789
Sheet3
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Thanks. Actually what I'm tying to do by using a formula is to put the Items in column A, then pull the month that have a value for the items by using a formula. So for example, Item A has sales in Feb and June, so the formula would put Item A in A7 and A8 and the month in B7 and B8 and the values in C7 and C8.
 
Upvote 0
I'm basically tying to create rows of data in column B7 to B14 for the months that are in column format in B1 to G1 with the items in Column A and the values in column C.
Is there a formula solution?
 
Upvote 0
I can use that approach for A2:A4 for the items. Not sure how to get it to match up with the months B1:G1 and the values.
 
Upvote 0
With the new dynamic arrays and functions in Excel there could be a solution.
 
Upvote 0
My attempt (long-winded formulas in places, and quite a few array-formulas):

Book8
ABCDEFG
1Jan SalesFeb SalesMar SalesApril SalesMay SalesJune Sales
2Item A1589
3Item B100102108456
4Item c1000789
5
6Expected Results
7Item AFeb Sales15Item AFeb Sales15
8Item AJune Sales89Item AJune Sales89
9Item BJan Sales100Item BJan Sales100
10Item BMar Sales102Item BMar Sales102
11Item BApril Sales108Item BApril Sales108
12Item BJune Sales456Item BJune Sales456
13Item cMar Sales1000Item cMar Sales1000
14Item cMay Sales789Item cMay Sales789
Sheet2
Cell Formulas
RangeFormula
D7D7=A2
E7E7=INDEX($B$1:$G$1,MATCH(FALSE,ISBLANK($B$2:$G$2),0))
F7F7=INDEX($B$2:$G$2,MATCH(FALSE,ISBLANK($B$2:$G$2),0))
D8:D14D8=IF(COUNTIF(D$6:D7,D7)<COUNTA(INDEX($B$2:$B$4,MATCH(D7,$A$2:$A$4,0)):INDEX($G$2:$G$4,MATCH(D7,$A$2:$A$4,0))),D7,INDEX($A$2:$A$4,MATCH(D7,$A$2:$A$4,0)+1))
E8:E14E8=INDEX($B$1:$G$1,SMALL(IF(NOT(ISBLANK(INDEX($B$2:$B$4,MATCH(D8,$A$2:$A$4,0)):INDEX($G$2:$G$4,MATCH(D8,$A$2:$A$4,0)))),COLUMN($B$1:$G$1)-COLUMN($A$1),1E+233),COUNTIF($D$7:D8,D8)))
F8:F14F8=INDEX(INDEX($B$2:$B$4,MATCH(D8,$A$2:$A$4,0)):INDEX($G$2:$G$4,MATCH(D8,$A$2:$A$4,0)),SMALL(IF(NOT(ISBLANK(INDEX($B$2:$B$4,MATCH(D8,$A$2:$A$4,0)):INDEX($G$2:$G$4,MATCH(D8,$A$2:$A$4,0)))),COLUMN($B$1:$G$1)-COLUMN($A$1),1E+233),COUNTIF($D$7:D8,D8)))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Fantastic. I didn't think this was possible. Thanks a lot. :) (y) You're right, the formulas to make this work are long. I have Office 365.
I wonder if having the filter, unique, sequence and other new functions would make this formula shorter.
 
Upvote 0
What about this?
Might fail if your range is large. How big are you likely to be dealing with?

pto160 2020-03-08 1.xlsm
ABCDEFG
1Jan SalesFeb SalesMar SalesApril SalesMay SalesJune Sales
2Item A1589
3Item B100102108456
4Item c1000789
5
6
7Item AFeb Sales15
8Item AJune Sales89
9Item BJan Sales100
10Item BMar Sales102
11Item BApril Sales108
12Item BJune Sales456
13Item cMar Sales1000
14Item cMay Sales789
15   
16   
17   
Sheet1
Cell Formulas
RangeFormula
A7:A17A7=IF(B7="","",TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("|"&TEXTJOIN("|",1,IF(B$2:G$4<>"",A$2:A$4,""))&"|","|","#",ROWS(A$7:A7)),"|","#",ROWS(A$7:A7)),"#",REPT(" ",1000)),1000,1000)))
B7:B17B7=IF(C7="","",TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("|"&TEXTJOIN("|",1,IF(B$2:G$4<>"",B$1:G$1,""))&"|","|","#",ROWS(B$7:B7)),"|","#",ROWS(B$7:B7)),"#",REPT(" ",1000)),1000,1000)))
C7:C17C7=IFERROR(TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("|"&TEXTJOIN("|",1,B$2:G$4)&"|","|","#",ROWS(C$7:C7)),"|","#",ROWS(C$7:C7)),"#",REPT(" ",1000)),1000,1000))+0,"")
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,777
Members
449,187
Latest member
hermansoa

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