Results 1 to 3 of 3

Thread: [VB2005] [Resolved] Sort excel file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    174

    Resolved [VB2005] [Resolved] Sort excel file

    Hello
    I am getting a "COMExecption unhandeld" at this line of code...

    Code:
      oSheet.Range("A2", "G" & EndRows).Sort("A2", Excel.XlSortOrder.xlAscending, "B2", Excel.XlSortOrder.xlAscending)
    EndRows is defined as the last row
    oSheet as excel worksheet
    Trying to ignore the first row (title) therefore the range is A2 => G....
    And trying to sort on two columns, A and B....

    What am i doing wrong ?

    Thanks !
    Last edited by Zoroxeus; Jan 3rd, 2008 at 10:08 AM.

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Sort excel file

    A quick look at the handy Excel Help for the Sort function would reveal that the Key parameters used to identify how to sort need to be either names or Range objects.

    In your case, I suspect you do not have a range named "A2", so you will need to use osheet.range("A2").

    Also, Excel will automatically recognise xlAscending. You don't need to use Excel.XlSortOrder.


    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    174

    Resolved [Solved] Re: Sort excel file

    Excellent thanks !
    i had actually looked at MSDN .. so i used "range("a2") and it did not work... did not know i had to use "osheet" as well
    thanks !

Posting Permissions

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



Click Here to Expand Forum to Full Width