export to excel and order
albertodfa
Member Posts: 15
I have created a program to export to excel and at the end i have written:
xlSheet.Range('a6:ad600').Select;
(to select the lines and columns to order)
Question:
now as I can say that I want is orderly for the column B and in ascending order?
Thanks and yours Sincerely
xlSheet.Range('a6:ad600').Select;
(to select the lines and columns to order)
Question:
now as I can say that I want is orderly for the column B and in ascending order?
Thanks and yours Sincerely
0
Comments
-
xlSheet.Range('a6:ad600').Sort(xlSheet.Range('b6'));Reference:
http://msdn.microsoft.com/library/defau ... 076391.asp0 -
If I wanted to select the sheet on more columns, besides the column B also the column A (in this order), as should I write the code?
And excuse if I take advantage, if I wanted some subtotals to every variation of A. and to write the total ones under the columns G and H as you must be writes the code?
I have seen the page that you have attached but I have not succeeded in writing a code what it works.
Hi and thanks even if you don't answer.
0 -
There's something broken about the syntax for sorting by multiple columns at the same time:
http://support.microsoft.com/default.as ... -us;229107
However, there is a trick that may work, implied by this reference:
http://support.microsoft.com/default.as ... -us;268007
This suggests that you achieve a multi-column sorting one column at a time, provided you sort the range starting with the 'least significant' column, and progressing to the 'most significant.'
In your example then, you would do the following:xlSheet.Range('a6:ad600').Sort(xlSheet.Range('a6')); xlSheet.Range('a6:ad600').Sort(xlSheet.Range('b6'));
As for sub-totals, there is a 'SubTotal' method that applies to a Range, but I haven't figured out how to call it from C/AL (yet...!). The SubTotal method requires three parameters -- the first and second are integers, but the third is an Array (COM type = SAFEARRAY). Unfortunately, C/AL does not support the conversion of C/AL arrays into COM SAFEARRAYs, so there is no easy way to provide this third required parameter.
When C/AL fails, the usual solution is to create a macro in the spreadsheet that will do the work. Then, from C/AL you can invoke the macro using xlApp.Run('MyMacroName');0 -
Thanks, I have tried as the example that you have written:
xlSheet.Range('a6:ad600').Sort(xlSheet.Range('b6'));
xlSheet.Range('a6:ad600').Sort(xlSheet.Range('a6'));
but so doing, it orders for the column "A" not maintaining the order of the column "B."
It serves that the relationship among the columns "A" and "B" both:
Order column "B" and order column "A"
Hi and thanks again0 -
Let me see if I understand your problem:
You have created a sheet with values in the range a6:ad600. You want to sort the rows in that range, first by column B, then by column A. If you were using the Excel user interface, you would first highlight the entire range a6:ad600, then click on the Excel menu item 'Data, Sort...'. In the Sort dialog box, in the 'Sort by' box, you would select 'Column B', and in the 'Then by' box, you would select 'Column A'.
If you do this using the Excel user interface, do you get the results you want?
If that is correct, then you can get the same result by sorting the range twice:- First, sort by column A (only)
- Then, sort by column B (notice that you have to do the 'separate' sorts in the reverse order)
xlSheet.Range('a6:ad600').Sort(xlSheet.Range('a6')); xlSheet.Range('a6:ad600').Sort(xlSheet.Range('b6'));Look at my suggestion carefully -- first column A, then column B -- I know this seems 'backwards', but I'm pretty sure it gets the job done.0 -
it was really this way. thanks 0
Categories
- All Categories
- 75 General
- 75 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions