Seems like an interesting task. I'd have done the code if I had the time. Meanwhile, you can try doing a lil something like this...
Import column contents into DataTable.
Compare the ASCI values of of these contents. Use the Asc function for doing so....
eg: Asc("Apple") ' Returns 65, compares 1st letter
Run a check for all from A to Z. (You may want to convert all to uppercase or lowercase for ease in comparing.). If more than one entry is found for each ASCI value, compare second letter and so on.... Keep storing your results into another column....run through the whole column in this fashion till you reach the ASCI value for Z.
Sorry I know this sort of description is confusing. Will try and post a sample code later.
Here's a quick way to do it based on a simple bubble sort logic. Or is it a shell sort? Can't remember for sure now, but it works:
DataTable.Import ("C:\Documents and Settings\YourFile.xls")
RowCount = DataTable.GetRowCount
LoopCount = 0
blnSwap = False
LoopCount = LoopCount + 1
For i = 1 to RowCount - LoopCount
x = DataTable("ColumnHeader")
y = DataTable("ColumnHeader")
If x > y Then ' Swap the two rows
DataTable("ColumnHeader") = x
DataTable("ColumnHeader") = y
blnSwap = True
Loop Until blnSwap = False or LoopCount = RowCount - 1
DataTable.Export ("C:\Documents and Settings\YourFile.xls")
I tested it by creating a quick unsorted file in excel and ran it though - it sorted just fine.
Be sure to replace the Import and Export lines with ImportSheet and ExportSheet or you might wipe out anything already in your datatable.
Also, if your table has more than one column, you will need to store every parameter in each row that will be swapped. I would do this with an array using stuff like this (I didn't include this array stuff in my simple test - too much work. So no guarantee on the syntax. I had to leave something for you to work out [img]images/icons/wink.gif[/img] ):
NumPrams = DTSheet.GetParameterCount 'put this before the do statement
'Swap this little loop in each spot you see DataTable("ColumnHeader")
'modify as appropriate for x or y and for assign or retrieve
For j = 1 to NumPrams
x(j) = DataTable("ColumnHeader")
Originally posted by Bond_421: Is there any way to sort Data in a particular coloumn by alphabetical order in an Excel file ?
Thanks in advance.
<font size="2" face="Verdana, Arial, Helvetica">I think it is easy to do so,
Just ighlight the Coloumn you want to Sort and from the Excel menu choose Data >Sort
then you can decide if u wanna sort them Asc or desc. or if u wanna sort all the columns in this sheet according to this column,...etc.
I hope am answering your question