Sorting multiple years by month

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
696
Office Version
  1. 365
Hi All

I know this is a big ask but I've been trying to find an easy way to do this over the weekend and havent got anywhere near what I'm trying to achieve.

I have a sheet "Installations" with 50k+ rows (and growing) and I want to sort the sheet with the dates descending (oldest date first) the dates are in column G which is the last used column.

The dates go back to 2017. Where I'm struggling is that I want to insert a row in between each month and add the Month and Year in this row column A.

So I would have the headers in row 1 columns A:G
Row 2 Column A would say Nov 2017
Row 3 to whatever was the last row in Nov 2017
Then last row for Nov 2017 + 1 would be Dec 2019 and so on up to the newest date at the bottom of the list.

Is this that is something that is achievable?

I'm really having difficulty with this, hence the post

Kind regards

Paul
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I always keep my data entry (or base data) apart from my desired outputs. And I like to use tables - it makes the formulas more readable and flexible.

MrExcelPlayground22.xlsx
ABCDEFGHIJKLMNOP
1DateItemThingOther ThingValue 1Value 2Value 3DateItemThingOther ThingValue 1Value 2Value 3
211/1/2017ABetaGamma384586Nov 2017
311/2/2017BBetaGamma76558511/1/2017ABetaGamma384586
411/3/2017CBetaGamma45723511/2/2017BBetaGamma765585
512/1/2017DBetaGamma9862311/3/2017CBetaGamma457235
612/2/2017EBetaGamma119045Dec 2017
712/3/2017FBetaGamma1015912/1/2017DBetaGamma98623
812/4/2017GBetaGamma50909212/2/2017EBetaGamma119045
91/1/2018HBetaGamma26345712/3/2017FBetaGamma10159
101/2/2018IBetaGamma37765812/4/2017GBetaGamma509092
111/3/2018JBetaGamma393454Jan 2018
121/5/2018KBetaGamma9138171/1/2018HBetaGamma263457
131/2/2018IBetaGamma377658
141/3/2018JBetaGamma393454
151/5/2018KBetaGamma913817
Sheet8
Cell Formulas
RangeFormula
J2:P15J2=LET(a,Table2,b,CHOOSECOLS(a,1),c,UNIQUE(EOMONTH(b,-1)+1),d,EXPAND(c,ROWS(c),7,""),e,VSTACK(d,a),SORT(e,1))
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
J2:J19Expression=K2=""textNO


The conditional formatting just changes the date format to Month-Year if the cell next to it is blank.
 
Upvote 0
Hi James

Thats a good way of doing it, I never thought it would be possible to do it with a formula.

Ideally I wanted to do it in vba as I want it to run as part of an already existing macro. I'm wondering I could adapt this to work in vba ??

Cheers

Paul
 
Upvote 0
I'm not too savvy with VBA - I only use it when I absolutely need to. But I don't think this approach would be needed for VBA. I'd just have excel sort the data by date and I'd have VBA go through each row in the selection, and when the month changed, insert a row and put the new month in that inserted row.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,109
Members
453,021
Latest member
Justyna P

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