• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to sort data in vba without sort function.

Hi Team

I have a data in excel file which I have attached. I want to sort the data but without using Sort function of VBA or excel.
I am unable to put any logic in it.

Please help if possible.

Data can go in any direction upwards or downwards.

Thanks and Regards
RatanB
 

Attachments

  • Sort_Test.xlsm
    12.6 KB · Views: 7
Oooo, I'll try.
This works only then area starts from Cell [A1] and area is max 2 column wide.
1st: checking how many values are in column-A. (a_max)
2nd: read active cell's positions, and which column is master
3rd: solve trigger for upwards or downwards
4th: if active cell is out of are - game over.
5th: running two loops, comparing two cell's values
master column is 'A' if activecell is 'A' ...
1st loop starts from 2 row (1row is title) to a_max-1
2nd loop start form next row (compare 1st value) to a_max
take two values =up/downward ( bigger/smaller), master column values
if comparing of values is true then swap both columns values
You can see 'better' from VBA-code and
You can run that code step by step too and You'll see how do this work.
I hope that You get an idea, did You?
 
Hi !

It's called Bubble Sort, the slowest way ‼ The more rows, the slower !

It's a very bad idea to not use inner Excel sort method, often the fastest !

For less than 1000 rows to sort, see Comb Sort,
faster than Bubble and easy to code.

Fastest could be Quick Sort (as Narayan's link), in a recursive way or not …
 
Back
Top