Sort by column in Excel from Excel Buffer
dn
Member Posts: 71
I'm using an excel buffer now. And want to sort data in column "L4".
Anyone who now how I can manage it with Excel Buffer.?
I found there is Xlrange..but how do I use it??
:-k
Anyone who now how I can manage it with Excel Buffer.?
I found there is Xlrange..but how do I use it??
:-k
0
Comments
-
By searching the forum about excel sort I found some nice info:
http://www.mibuso.com/forum/viewtopic.p ... excel+sort
http://www.mibuso.com/forum/viewtopic.p ... excel+sort
For example to sort by column B try:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'));
I can't help you exactly on where to put the code to sort the column in the excel buffer table, but I think at the end of the routine CreateSheet, like:Function CreateSheet..... . . . XlWrkSht.Range('A' + FORMAT(1) + ':' + xlColID + xlRowID).Columns.AutoFit; XlWrkSht.Range('A' + FORMAT(1) + ':' + xlColID + xlRowID).Sort(XlWrkSht.Range('L4')); END; END; Window.CLOSE;It might do the trick...0 -
nice..I'll try...thx 0 -
:-k ..hm the problem is I have headline on row above.
If i use
XlWrkSht.Range('A' + FORMAT(1) + ':' + xlColID + xlRowID).Sort(XlWrkSht.Range('L4'));
Then the content in Excel look no good
0 -
What do you mean look no good? The headers went to the bottom?
Experiment a little with the parameters about the xlColID + xlRowID and the XlWrkSht.Range('L4')...
The whole concept is to select all the data you have and sort them at L4...
Is the L1,L2,L3 headers? If yes then you could try freeze panes before sorting, so that the headings stay at the top...
Or choose 'A'+FORMAT(4) if your first 3 lines are headers...
Anyway, practice makes perfect...0 -
Yes..Line 3 is headline..
I've tried with
XlApp.Range('A3').Select; //...
XlApp.ActiveWindow.FreezePanes := TRUE;
XlWrkSht.Range('A' + FORMAT(4) + ':' + xlColID + xlRowID).Sort(XlWrkSht.Range('L4'));
but the result is still odd
.. #-o 0 -
Hmmm....
What do you mean odd?
Where do you export to excel from?
Analysis By Dimensions?0 -
Hi
It's a new report I created to export invoices to Excel.
I want to sort Margin in percent in Column L4 via Excel Buffer0 -
Hi...
Which report did you consult to make our own? I think Report 113 is a very nice example to use to make your own report export to excel.
I tested the following code with report 113 (Customer/Item) and it worked very well...Function CreateSheet . . . UNTIL NEXT = 0; XlWrkSht.Range(GetExcelReference(5) + ':' + xlColID + xlRowID).Columns.AutoFit; XlWrkSht.Range('A2').Select;//added this line XlApp.ActiveWindow.FreezePanes := TRUE;//added this line XlWrkSht.Range('A' + FORMAT(2) + ':N65000').Sort(XlWrkSht.Range('D2'));//added this line END; IF UseInfoSheed THEN BEGIN IF InfoExcelBuf.FIND('-') THEN BEGIN XlWrkSht := XlWrkBk.Worksheets.Add(); . . .To make it better you must make a new function in excel buffer table with name like:Function SortColumn(StartColumn:code;StartRow:Integer;EndColumn:Code;EndRow:Integer;SortColumn:Code); BEGIN XlWrkSht.Range(StartColumn+FORMAT(StartRow-1)).Select; XlApp.ActiveWindow.FreezePanes := TRUE; XlWrkSht.Range(StartColumn+FORMAT(StartRow) + ':'+EndColumn+FORMAT(EndRow-1)).Sort(XlWrkSht.Range(SortColumn+FORMAT(StartRow))); END;
And in your report, after calling the CreateSheet and before the GiveUserControl you should execute something like:
SortColumn('A',2,'Z',65000,'B');
to freeze panes and sort the column B from row 2 and on...
I suggest you study the report 113 on how it exports to excel... It is all in routines...0 -
thx u...0
-
Hi Arhontis,
The code works fine, how i can sort it in ascending order in excel.
Any one ?0 -
Try something like:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'));0 -
Hi Arhontis,
I have created a function in excel buffer like you said. The sorting is working perfectly =D> . The sorting is done in ascending order.
But i need the sorting order in Descending order. i have to create one more variable in the function with which i can tell the function to make the sorting order (xlDescending. Sorts Key1 in descending order. ) How can i achieve this please give your suggestion.0 -
Hi
Try to use the following code properly in your function:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'),1); // Sorting in ascending order.
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'),2); // Sorting in descending order.
Best regards0 -
Thanks Chi,
It worked i have added one more variable in my function which will decide the Sort order. Thanks very much for your valuable replay.
SortColumn(StartColumn : Code[10];StartRow : Integer;EndColumn : Code[10];EndRow : Integer;SortColumn : Code[10];SortOrder : Integer)
BEGIN
XlWrkSht.Range(StartColumn+FORMAT(StartRow-1)).Select;
XlApp.ActiveWindow.FreezePanes := TRUE;
XlWrkSht.Range(StartColumn+FORMAT(StartRow) + ':'+EndColumn+FORMAT(EndRow-1)).Sort(XlWrkSht.Range(SortColumn+FORMAT(StartRow)),SortOrder)
END;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
