Sunday, December 4, 2011

How to sort a column by date in Visual Basic?

I'm writing a financial spreadsheet program so that users can add transactions to a spreadsheet, and it calculates their previous and new balances. its very simple. but basically i need to write some code for when the user presses OK to add the transaction that automatically puts the new transaction in order of date.





for example if there is already an entry for 1st and 3rd january 2010, and a user adds an entry for 2nd jan 2010, i'd like the entry to be sorted so that it goes in between the 2.





thanks in advance|||One way to do it is to sort the rows after each entry, or after any given event for that matter. The source below shows a discussion on adding sorting to your macro. This is excel, right?





If not, you could load the "spreadsheet" into a hashtable or recordset and then sort it by date. If this is a SQL setup (SQL, Oracle, mySQL), select statements already have sorting capabilities.





What I'm saying is, other than an in-memory table, the best way to sort is in the native app, imo.

No comments:

Post a Comment