priyanka_mehta Posted October 9, 2009 Share Posted October 9, 2009 Hi all, I need some help with sorting programming in AutoCAD VBA. I have an excel sheet saved as .csv. I need to sort this .csv file in ascending order based on a particular column. The location of that reference column is also fixed. Please find the attached .csv. In this eg., I have six columns. I need to sort the whole sheet in ascending order based on the sixth column i.e. Column F. Please help! Regards, Priyanka New Microsoft Excel Worksheet.zip Quote Link to comment Share on other sites More sharing options...
SEANT Posted October 9, 2009 Share Posted October 9, 2009 What would be the end result? By that I mean: If the end result is a .CVS or .XLS then sorting the original with Excel would be quite easy. If Excel (or something similar) is no longer part of the process then I’d suggest: Set up a Type to contain individual rows of data Public Type CVSData A As Integer B As Double C As Double D As String E As String F As Double End Type Create a new Collection. Start iterating through the CVS file to create an instance of CVSData for each row. Dim typRow as CVSData For the first line just add the typRow to the Collection. Collection.Add typRow For subsequent lines, iterate through the items already in the collection to find the first place where Collection.Item.F > typRow.F. The Collection Add method has these optional parameters Collection.Add Item, [Key], [before], [After] So: Then Collection.Add typRow, , Collection.Item.F Should create an ascending ordered collection. Quote Link to comment Share on other sites More sharing options...
priyanka_mehta Posted October 9, 2009 Author Share Posted October 9, 2009 Thanks Seant, I ll try doing this. Actually the end result is a .csv itself. The problem is that this table is obtained as an output of one of my code. This is all being done at the back end, and finally i ve got to use this .csv to plot in as AutoCAD objects. I dont want to ask the user to go to the original file, open it and edit it. I ll try by the procedure you've recommended. Although this kind of programming, sorting and all, is a slightly heavy for me. I might expect some help in the middle of the code if i get stuck ! Thanks a lot, Priyanka Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.