Change Formatting of Data

schwang

New Member
Joined
Oct 31, 2018
Messages
3
Hey all!

I am processing data downloaded from a Bloomberg terminal for over 8000 firms, but I am experiencing difficulty. The data set is in the current format:

AAPLBAC
1/1/20180.0430-0.0131
1/2/20184.69580.1438
1/3/20180.8888-0.1045
1/4/20181.0708-0.4836
1/5/20182.5748-0.3809

<tbody>
</tbody>


I need the data to be in the following format:

DateTickerRET
1/1/2018AAPL0.0430
1/2/2018AAPL4.6958
1/3/2018AAPL0.8888
1/4/2018AAPL1.0708
1/5/2018AAPL2.5748
1/1/2018BAC-0.0131
1/2/2018BAC0.1438
1/3/2018BAC-0.1045
1/4/2018BAC-0.4836
1/5/2018BAC-0.3809

<tbody>
</tbody>

I'm sure there's a way to do this using OFFSET and other tools but I can't figure it out. If need be, VBA is fine too, but formulas would be preferred if at all possible. Thanks in advance!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
using PowerQuery (Get&Transform):

DateAAPLBACDateAttributeValue
01/01/2018​
0.043​
-0.0131​
01/01/2018​
AAPL
0.043​
01/02/2018​
4.6958​
0.1438​
01/01/2018​
BAC
-0.0131​
01/03/2018​
0.8888​
-0.1045​
01/02/2018​
AAPL
4.6958​
01/04/2018​
1.0708​
-0.4836​
01/02/2018​
BAC
0.1438​
01/05/2018​
2.5748​
-0.3809​
01/03/2018​
AAPL
0.8888​
01/03/2018​
BAC
-0.1045​
01/04/2018​
AAPL
1.0708​
01/04/2018​
BAC
-0.4836​
01/05/2018​
AAPL
2.5748​
01/05/2018​
BAC
-0.3809​

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Date", type date}, {"AAPL", type number}, {"BAC", type number}}),
    Unpivot = Table.UnpivotOtherColumns(Type, {"Date"}, "Attribute", "Value")
in
    Unpivot[/SIZE]
 
Upvote 0
For those reading this thread who do not use PowerQuery, here is a macro solution that should work (set WS1 to the data sheet and WS2 to the output sheet)...
Code:
[table="width: 500"]
[tr]
	[td]Sub RearrangeData()
  Dim Col As Range, Rw As Long
  Dim WS1 As Worksheet, WS2 As Worksheet
  Dim Dates As Variant, Ticker As Variant, RET As Variant
  Set WS1 = Sheets("[B][COLOR="#FF0000"]Sheet1[/COLOR][/B]")
  Set WS2 = Sheets("[B][COLOR="#FF0000"]Sheet2[/COLOR][/B]")
  Dates = WS1.Range("A2", WS1.Cells(Rows.Count, "A").End(xlUp))
  Application.ScreenUpdating = False
  WS2.Range("A1:C1") = Array("Date", "Ticker", "RET")
  For Each Col In WS1.Range("B2", WS1.Cells(2, Columns.Count).End(xlToLeft)).Columns
    Rw = WS2.Cells(Rows.Count, "A").End(xlUp).Row + 1
    WS2.Cells(Rw, "A").Resize(UBound(Dates)) = Dates
    WS2.Cells(Rw, "B").Resize(UBound(Dates)) = WS1.Cells(1, Col.Column).Value
    WS2.Cells(Rw, "C").Resize(UBound(Dates)) = WS1.Cells(2, Col.Column).Resize(UBound(Dates)).Value
  Next
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
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