Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

Need a hand in sorting this excel data in a weird way!!

I have data in following manner:

Name  |     Stat     |     Value

Emp1  |     outc     |      2
Emp1  |     inc      |      NA

Emp2  |     outc     |      10
Emp2  |     inc      |      4

Emp3  |     outc     |      6
Emp3  |     inc      |      20



Now I need to sort this data on 'out' value in descending order but at the same time, the emp name block is to be intact i.e other parameter values will not be sorted. Output hence will be

Name  |     Stat     |     Value

Emp2  |     outc     |      10
Emp2  |     inc      |      4

Emp3  |     outc     |      6
Emp3  |     inc      |      20

Emp1  |     outc     |      2
Emp1  |     inc      |      NA


Please help!! I am using excel vba. Any suggestion will be very helpful!

What I have tried:

I have unmerged the emp cells and then sort the data. But the block is not remaining intact.
Posted
Updated 20-Jul-17 1:14am

1 solution

The easiest would be to create a sort helper column:

assuming Name is col C, Stat is col D and Value is col E the formula in row 5 would be:

=TEXT(IF(C5=C4,E4,E5),"000000")&C5


The sort would then be on the column this formula is in (Descending) and the second key column would be the Stat column (Descending).

So the formula... if the Emp# is the same as the row above, use the row above value, otherwise use the value on the same row.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900