|
-
Nov 13th, 2007, 03:39 PM
#1
Thread Starter
Addicted Member
[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.
-
Nov 13th, 2007, 04:12 PM
#2
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
-
Nov 13th, 2007, 05:41 PM
#3
Thread Starter
Addicted Member
[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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|