Jump to content

sort ascending using VBA


priyanka_mehta

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...