Board index » delphi » How do you sort ranges in Excel???

How do you sort ranges in Excel???

Hi,

A).  I need your help to sort a range of cells by a specific column in excel
from Delphi 3.0, I have some of my code included, the first FormatData works
fine but I do not know the instructions to SortData by a column.

B).  Also how do you tell Excel to save the file with a specific name_file?

THIS WORKS VERY WELL
Procedure TBillToExcelFrm.FormatData;
var
  Range : Variant;
begin
  Range := XLApp.Workbooks[1].WorkSheets['Billing  Data'].Range['D1:F20'];
  Range.NumberFormat:='$#,##0.00';
end;

THIS DOES NOT WORK AT ALL
Procedure TBillToExcelFrm.SortData;
var
  Range : Variant;
begin
  Range := XLApp.Workbooks[1].WorkSheets['Billing  Data'].Range['D1:F20'];
  Range.Sort.Key1:='B2';  { I NEED YOUR HELP HERE}
end;

Thank you

Jose M. Varela

 

Re:How do you sort ranges in Excel???


Try this:
      Range.Sort(Key1:='B2');

Quote
JMV wrote:
> Hi,

> A).  I need your help to sort a range of cells by a specific column in excel
> from Delphi 3.0, I have some of my code included, the first FormatData works
> fine but I do not know the instructions to SortData by a column.

> B).  Also how do you tell Excel to save the file with a specific name_file?

> THIS WORKS VERY WELL
> Procedure TBillToExcelFrm.FormatData;
> var
>   Range : Variant;
> begin
>   Range := XLApp.Workbooks[1].WorkSheets['Billing  Data'].Range['D1:F20'];
>   Range.NumberFormat:='$#,##0.00';
> end;

> THIS DOES NOT WORK AT ALL
> Procedure TBillToExcelFrm.SortData;
> var
>   Range : Variant;
> begin
>   Range := XLApp.Workbooks[1].WorkSheets['Billing  Data'].Range['D1:F20'];
>   Range.Sort.Key1:='B2';  { I NEED YOUR HELP HERE}
> end;

> Thank you

> Jose M. Varela

Other Threads