+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Full Member
    Using
    Map 3D 2005
    Join Date
    Dec 2008
    Posts
    33

    Default sort ascending using VBA

    Registered forum members do not see this ad.

    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
    Attached Files

  2. #2
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    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

    Code:
    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.

  3. #3
    Full Member
    Using
    Map 3D 2005
    Join Date
    Dec 2008
    Posts
    33

    Default Sorting using VBA

    Registered forum members do not see this ad.

    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

Similar Threads

  1. Sort ss by y value
    By Small Fish in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 29th May 2009, 01:28 pm
  2. Object Sort Method?
    By CADTutor in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 6
    Last Post: 23rd Sep 2008, 10:36 pm
  3. Sort a selection set
    By mckee in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 28th Jun 2007, 07:16 pm
  4. EASY VL-SORT question
    By TuFoFi in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 19th Nov 2005, 11:25 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts