Excel XP sorting issue

R

Richard Clarke

Hi

I am performing a sort programatically in Excel 2002 on Windows XP

The line of code to sort is as follows:

Range(Cells(15, 1), Cells(endrow,
Range("iNonQualStatus").Column)).Sort Key1:=Range("iItemType"),
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=ordercustomnumber, MatchCase:=False,
Orientation:=xlTopToBottom

This throws the following error:

Sort Method of Range class failed

The sheet is protected both programatically and using Excel's protect
option from the menus.

No matter what I try regarding setting different protections at
run-time or saving the sheet with different protections, whenever I
hit the line of code above, the allowsorting propery is false.

In order to test sorting I created a new workbook and sheet to test
the sorting functionality and even this fails - with no protections,
and allowsorting reporting true when interrogated at runtime (although
this time the error is 1004 Application-defined or object-defined
error).

When Sheets("Input").Protection.AllowSorting is interrogated just
before the sort is called, it is always false, even if I unprotect the
sheet using code the line before the sort call. This leads me to
believe that something is preventing the allowsorting to become true.

Can anyone suggest why this doesn't work in either scenario?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top