Link to home
Start Free TrialLog in
Avatar of raphael DC
raphael DC

asked on

Problem for sorting more than 3 columns on Excel file, using Win32::OLE perl

Hi,

I am using the Sort function in the Win32::OLE package for Perl.
I would like to sort all my columns based on the first 4 columns (sort by: col1 then col2... col4)
For now I am able to sort by the 3 first columns but when I try to do on 4 I get an error in GetIDsOfNames for "Sort" at MyFile.pl

Here's my code:


my $SortOrd1 = $SheetC->Range("A2");
my $SortOrd2 = $SheetC->Range("B2");
my $SortOrd3 = $SheetC->Range("C2");
my $SortOrd4 = $SheetC->Range("D2");

my $Range = "A" . ($dcmRowA+2) . ":" . chr($LastColC+64) . ($LastRowC);
my $Selection = $SheetC->Range($Range);
my %hash = (Key1 => $SortOrd1, Order1 => xlAscending, Key2 => $SortOrd2, Order2 => xlAscending,  Key3 => $SortOrd3, Order3 => xlAscending, Key4 => $SortOrd4, Order4 => xlAscending);
$Selection->Sort(\%hash);

Open in new window



again, if I remove the Key4 => $SortOrd4, Order4 => xlAscending) the code works fine, but I need to sort according to the first 4 columns

Would you know why I get this error with 4 criterias but not 3?

Thanks in advance
Have a good day :)

Rapha
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rgonzo1971
Rgonzo1971

Hi,

It is probably limited to 3 keys then sort first with the 4th key and then with 1st, 2nd and 3rd at once

Regards
Avatar of raphael DC

ASKER

Thanks Rob,

It may have to do with that indeed. Even though i'm using excel 2013, the Win32::OLE may be coded for Excel 2003.
I will try to find another way to sort ;)

Have a great day :)
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Rob Henson (https:#a42336578)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

broomee9
Experts-Exchange Cleanup Volunteer