Convert Horizontal Data to Vertical

twilson4

New Member
Joined
Jul 27, 2015
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a long string of data that is laid out horizontally and I am trying to find a way (without VBA) to relatively easily convert it to be vertically stacked. Below is a small example of what I need to be able to do on a much larger scale.

If I set up the horizontal spreadsheet to have the 6 rows for each 1 row of data on the horizontal, is there a formula that allows me to look up a combination of styles and types from the vertical table and grab them from both the column and row in the horizontal table?

DepartmentCategoryStyleJan PlanJan ActJan VarFeb PlanFeb ActFeb Var
MenOuterwearABC2002505020025050
MenOuterwearDEF300250-50300250-50
MenOuterwearGHI400350-50400350-50
DepartmentCategoryStyleTypeValue
MenOuterwearABCJan Plan200
MenOuterwearABCJan Act250
MenOuterwearABCJan Var50
MenOuterwearABCFeb Plan200
MenOuterwearABCFeb Act250
MenOuterwearABCFeb Var50
MenOuterwearDEFJan Plan300
MenOuterwearDEFJan Act250
MenOuterwearDEFJan Var-50
MenOuterwearDEFFeb Plan300
MenOuterwearDEFFeb Act250
MenOuterwearDEFFeb Var-50
MenOuterwearGHIJan Plan400
MenOuterwearGHIJan Act350
MenOuterwearGHIJan Var-50
MenOuterwearGHIFeb Plan400
MenOuterwearGHIFeb Act350
MenOuterwearGHIFeb Var-50

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
twilson4,

I know that you asked for a formula solution, but, none of the formula Guru's have responded yet.

Here is a macro solution for you to consider that is based on your two flat text displays, that uses two arrays in memory, and, will adjust to the number of raw data rows, and, columns.

I assume that your raw data is in worksheet Sheet1, and, that the results will be written to worksheet Results.

I assume that both worksheets already exist, and, you can change the worksheet names in the macro.

Your raw data is in worksheet Sheet1, range A1:I4.

The results will be in worksheet Results, range A1:E19.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub Convert_Horizontal_Data_to_Vertical()
' hiker95, 09/08/2017, ME1022065
Application.ScreenUpdating = False
Dim w1 As Worksheet, wr As Worksheet
Dim a As Variant, lr As Long, lc As Long, n As Long, i As Long, c As Long
Dim o As Variant, j As Long
Set w1 = Sheets("Sheet1")   '<-- you can change the sheet name here
Set wr = Sheets("Results")  '<-- you can change the sheet name here
With w1
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  a = .Range(.Cells(1, 1), .Cells(lr, lc))
  n = Application.Count(.Range(.Cells(2, 4), .Cells(lr, lc)))
  ReDim o(1 To n + 1, 1 To 5)
End With
j = j + 1: o(j, 1) = "Department": o(j, 2) = "Category"
o(j, 3) = "Style": o(j, 4) = "Type": o(j, 5) = "Value"
For i = 2 To UBound(a, 1)
  For c = 4 To UBound(a, 2)
    j = j + 1: o(j, 1) = a(i, 1): o(j, 2) = a(i, 2): o(j, 3) = a(i, 3)
    o(j, 4) = a(1, c): o(j, 5) = a(i, c)
  Next c
Next i
With wr
  .UsedRange.ClearContents
  .Range("A1").Resize(UBound(o, 1), UBound(o, 2)) = o
  .UsedRange.Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the Convert_Horizontal_Data_to_Vertical macro.
 
Upvote 0
I will give the macro a try...my data is significantly larger than the example I gave so will see if I can get it to work.

To the responses asking if it was a Transpose question...yes it is on it's most basic need. However, I need it to transpose the columns to rows while duplicating what is already in the rows. All the while my data will refresh periodically making it something I am trying to get set up through formulas so it can happen automatically.

Appreciate everyone's time and assistance...
 
Upvote 0
I will give the macro a try...my data is significantly larger than the example I gave so will see if I can get it to work.

twilson4,

Make sure that you try the macro on a copy of your workbook.
 
Upvote 0
twilson4,

Make sure that you try the macro on a copy of your workbook.

I ended up getting an Index Match Match formula to work using this "how to"...

http://www.mbaexcel.com/excel/how-to-use-index-match-match/

[FONT=&quot]= INDEX ( [/FONT][FONT=&quot]array[/FONT][FONT=&quot] , MATCH ( [/FONT][FONT=&quot]lookup_value[/FONT][FONT=&quot] , [/FONT][FONT=&quot]lookup_array[/FONT][FONT=&quot] , 0 ) , MATCH ( [/FONT][FONT=&quot]lookup_value[/FONT][FONT=&quot] , [/FONT][FONT=&quot]lookup_array[/FONT][FONT=&quot] , 0 ) )


[/FONT]
Next question...does anyone know how to reference cells in sequential orders...ie( a1, a2, a3...) when referencing them in b1, b10, b20, b30...? I would like to be able to copy paste down in column B but because it requires a gap instead of going to a2, it references a10.

Is this possible?
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

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