Vba macro: Normalize data
Debra has a great post and video about normalizing data for excel pivot table. This post describes a macro that normalizes data for excel pivot tables.
VBA macro
- Press Alt+ F11
- Right click your workbook in project explorer
- Click Insert
- Click Module
- Paste macro code below to module
- Exit VB Editor
Sub NormalizeData()
Dim Rng As Range
Dim WS As Worksheet
On Error Resume Next
Set Rng = Application.InputBox(Prompt:="Select a range to normalize data" _
, Title:="Select a range", Default:=ActiveCell.Address, Type:=8)
On Error GoTo 0
If Rng Is Nothing Then
Else
Application.ScreenUpdating = False
Set WS = Sheets.Add
i = 0
For r = 1 To Rng.Rows.Count - 1
For c = 1 To Rng.Columns.Count - 1
WS.Range("A1").Offset(i, 0) = Rng.Offset(0, c).Value
WS.Range("A1").Offset(i, 1) = Rng.Offset(r, 0).Value
WS.Range("A1").Offset(i, 2) = Rng.Offset(r, c).Value
i = i + 1
Next c
Next r
WS.Range("A:C").EntireColumn.AutoFit
Application.ScreenUpdating = True
End If
End Sub
Download excel *.xlsm file


















Hi,
I have a worksheet with following columns, namely,
Trans Date Issue Date Deposit Withdrawal Balance
01-Jan-12 01-Jan-12 50,000,000 0 50,000,000
02-Jan-12 01-Jan-12 80,000,000 0 130,000,000
10-Jan-12 01-Jan-12 0 90,000,000 40,000,000
15-Jan-12 01-Jan-12 0 40,000,000 0
I want to calculate running balance for deposit / withdrawal based on particular issue date, as shown in the example
worksheet.
Please tell me how to achieve this task.
Your help in this regard shall be highly appreciated.
Cheers!
Muhammad Nadeem
Hi,
The add-in here :
http://kb.tableausoftware.com/articles/knowledgebase/addin-reshaping-data-excel
does the same, with more powerful tricks included.
No need to have Tableau installed to run it.
Thanks for sharing.
Please see link below for an unpivot add-in, which can process large, more complex data sets fast and/or multiple similar data sets sequentially e.g. convert 100s balance sheets.
http://www.spreadsheet1.com/unpivot-data.html
Muhammad Nadeem Bhatti,
See attached file:
running-balance-on-a-issue-date.xlsx
Edouard and Petros,
thanks for sharing!
Hi Oscar,
Thanks for sharing the excel file for running balance on a issue date.
Can you please suggest a way for keeping the running balance in the table instead of making a separate issue date search and show result.
Look forward for your reply.
Grateful for your help.
Cheers!
Muhammad Nadeem Bhatti.
Muhammad Nadeem Bhatti,
See attached file:
running-balance-table.xlsx