Board index » delphi » Sort Excel worksheet

Sort Excel worksheet

Hi all!

I have written an ap that writes a lot of data to a new excel worksheet. But if I want to sort the worksheet using something
like Workbooks[1].sheets[1].range['A1:C3'].Sort( Key1 = 'A1' etc.etc.) it doesn't work.

I recorded a macro and then copied and modified the vba code into my delphi program, but it just doesn't work.
Can anyone give me a good example of how to sort columns in Excel?

A reply to my email adress ( hharm...@worldonline.nl ) would be really appreciated!

Thanks for any help.

Barry

 

Re:Sort Excel worksheet


<<Barry:
Can anyone give me a good example of how to sort columns in
Excel?

Quote

The trouble with the Sort method is that some of the
parameters that ought to be optional aren't, in early
binding. If you have a Worksheet, WS, this should work:

  WS.Range['A1', 'I10'].Sort(WS.Range['A1', 'A10'],        
           xlAscending, EmptyParam, EmptyParam,
           xlDescending, EmptyParam, xlAscending,
           xlNo, EmptyParam, True, xlTopToBottom,
           xlSyllabary);

You can also use a variant, in order to avoid some of thos
parameters:

var
  Rng: OleVariant;
..
  Rng := WS.Range['A1', 'I10'];
  Rng.Sort(WS.Range['A1', 'A10']);

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads