Monks,
I'm using Win32::OLE to do some excel work...
I have a worksheet which i need to sort.
However, I do not want to sort the entire sheet.
I only want to sort columns M & N.
I recorded a macro to see what excel does..here's that code
Columns("M:N").Select
Selection.Sort Key1:=Range("M2"), Order1:=xlAscending, Header:=xlY
+es, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
+_
DataOption1:=xlSortNormal
Here is what I do with my Perl code for it (snippet)
$Range_new1 = $Sheet->Range("m2");
$Range_new2 = $Sheet->Range("n2");
$Excel->Selection->Sort({Key1 => $Range_new1,
Order1 => xlAscending,
Key2 => $Range_new2,
Header=>xlYes,
OrderCustom=>1,
MatchCase => False,
DataOption1 => xlSortNormal});
However, this does not sort only columns M & N but the whole sheet... What am I missing?
Is there any function to select only columns M & N???
Update::
I wanted to know how to put 'Columns("M:N").Select' in PERL OLE and only sort those 2 columns and leave the other columns as it is.
This is my updated code
$Range_new1 = $Sheet->Range("m:n");
$Range_new2 = $Sheet->Range("n2");
$Excel->Selection->Sort({Key1 => $Range_new1,
Order1 => xlAscending,
#Key2 => $Range_new2,
Header=>xlYes,
OrderCustom=>1,
MatchCase => False,
DataOption1 => xlSortNormal});
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.