VBA to auto-pivot and arrange 3 columns of data

alexcon

New Member
Joined
Dec 29, 2017
Messages
20
[TABLE="width: 500"]
<tbody>[TR]
[TD]Description[/TD]
[TD]Date[/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]Item 1[/TD]
[TD]2016/01/26[/TD]
[TD]0.01399[/TD]
[/TR]
[TR]
[TD]Item 2[/TD]
[TD]2016/07/18[/TD]
[TD]0.17513[/TD]
[/TR]
[TR]
[TD]Item 3[/TD]
[TD]2016/06/13[/TD]
[TD]0.02468[/TD]
[/TR]
[TR]
[TD]Item 1[/TD]
[TD]2016/08/15[/TD]
[TD]0.01452[/TD]
[/TR]
</tbody>[/TABLE]


This runs down thousands of rows with various dates and values and descriptions in a sheet called "Data Capture". The descriptions periodically repeat but at different dates and values (e.g. Item 1). More rows are constantly added, so a VBA macro to auto-pivot and arrange as follows into an already existing sheet called "Clean Pivot" would help a lot.

A simple manual pivot results in the following: [edit: values are changed from Sum to Avg in the pivot]

https://ibb.co/droSzw

And after a manual cleanup it results in this usable format:

https://ibb.co/j0VwsG

The cleanup involves

1) removing the first to rows,
2) removing all the "Total" and "Grand Total" columns.
3) removing the "1900" column. (Don't know why it's there in the first place)
4) Renaming "Row Labels" to "Description"
5) Changing the date format to MMM-YY so for example that it runs Dec-16 (Dec 2016) over to Jan-17 (Jan 2017) seamlessly.
6) Converting it from a Range to a Table.

Once it's in this usable format, I've got a number of other macros that I can run.
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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