Log in

View Full Version : Macro to Sort 4 days data, Keep Sequential Data and Delete rest



analyst
01-08-2014, 03:00 PM
I currently use Excel Version 2003 (It is okay, even if macro is for Excel2007)

Data Range A:O

Row data could differ from 2,000 to 6,000 rows (having 4 days data)

Column O has Date Data in format dd-mmm-yy

All data in its current form is arranged in Ascending order, based on Date Data in Column O

I need a VBA Macro Procedure that could-

1) Sort Data in Column A:O,
first on Column B, then sort on
Column D, then sort on
Column O, then sort on
Column C
2) Above would line up 4 days dataset based on date, but few record could be for less than 4 days, say, only for 1st, 2nd and 3rd days, but not for 4th day, or for 1st,3rd,and 4th day, but not for 2nd day and so on, which should be deleted, as each record set should be for 4 days, in continuity. Shortly, Each data should be for minimum 4 days, if not, entire row should be deleted.

For Clarity purpose in attached workbook having sample data,
a) Sheet1 (Named as - RAWDATA) - Contains RAW data
b) Sheet2 (Named as - Sorted on B D O C) shows, how data should be organised after sorting per criteria given in 1) above,
c) Sheet2 (Named as - Sorted on B D O C) Highlighted rows in Grey Color shows where data is not for 4 days sequentially, and hence such row should be deleted
d) Sheet3 (Output) Final Output data is given, just for sample basis, each data set for 4 days, arranged sequentially.

Data in Sheet3 is just sample output, done manually currently, so restricted till rows 72

Macro should process and bring the desired data in Sheet1 itself, where raw data was residing originally.

Admin
01-08-2014, 03:48 PM
Hi

Is it similar to this http://www.excelfox.com/forum/f2/retain-set-of-4-days-data-based-on-row-data-in-3-columns-and-delete-rest-1606/ ?

analyst
01-08-2014, 04:12 PM
Yes Sir, bit similar to that, but when I am sorting data, I feel, some of the data, that were meeting my criteria is also getting deleted, not sure, how. But , given that code, when I am attempting to sort data on Column, B, D, O, and then on C, it gives some vague result, or some silly mistake, I'm making. Can you plz append a few line to that code, that would sort data on Columns B, then on Column D, O, and lastly on Column C. Apology

I guess, in current query, data is not sorted, which is first required to be done, and then code given at http://www.excelfox.com/forum/f2/retain-set-of-4-days-data-based-on-row-data-in-3-columns-and-delete-rest-1606/ this should follow.

analyst
01-08-2014, 04:16 PM
I just tried arranging data (thru SORT) first, and then running code, you named as kTest, but getting some vague answer. I am relooking at my data structure, and find no flaw in your code, given earlier kTest.

I've rechecked my data arrangment and have done sorting. KTest is perfectly alright. There was no intetion to create SPAM, please delete this thread. I apologise for my mistake.

Admin
01-08-2014, 04:40 PM
Hi

Your raw data and the sorted data is not matching anymore.

analyst
01-08-2014, 04:54 PM
I've goof up. Now sorted, have plugged in the macro to arrange data to sort properly, and then calling kTest to do rest of the things. Thanks.

I regret to have consumed forum, time and resource, kindly excuse.