ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort problem - perplexing and annoying in the extreme (https://www.excelbanter.com/excel-programming/427557-sort-problem-perplexing-annoying-extreme.html)

Brett

Sort problem - perplexing and annoying in the extreme
 
Hello out there. I have a line of code to sort a range that has only pasted
values in it, there are no formulas whatsoever.
F_REF.Range("AA54:AE72").Sort Key1:=F_REF.Range("AE72"), _
Order1:=xlAscending, Key2:=F_REF.Range("AB72"), Order1:=xlAscending

F_REF has previously been set to the sheet name.

Now sometimes this line of code works, and sometimes it doesn't (at the
moment it has decided not to work at all). Normally, for this macro, I have
calculation off, but in debugging I have tried calc to auto and it doesn't
make any difference (and nor should it, because they are values only).

What is particularly aggravating about this "non-sorting" is that it ALWAYS
works if I either execute the line by stepping through the code, or if I run
a little stand-alone macro that executes the sorting macro.

How can this possibly be please? Regards, Brett

Brett

Sort problem - perplexing and annoying in the extreme
 
In the interim I've spotted a couple of things in the line of code. I hadn't
specified Order2 for the second key, and both keys were set to the last row
rather than the first (AE72 should be AE54 et al). HOWEVER, that still
doesn't explain why it works when it's done manually, which means that I'm
still looking for an explanation of what might be going on.

"Brett" wrote:

Hello out there. I have a line of code to sort a range that has only pasted
values in it, there are no formulas whatsoever.
F_REF.Range("AA54:AE72").Sort Key1:=F_REF.Range("AE72"), _
Order1:=xlAscending, Key2:=F_REF.Range("AB72"), Order1:=xlAscending

F_REF has previously been set to the sheet name.

Now sometimes this line of code works, and sometimes it doesn't (at the
moment it has decided not to work at all). Normally, for this macro, I have
calculation off, but in debugging I have tried calc to auto and it doesn't
make any difference (and nor should it, because they are values only).

What is particularly aggravating about this "non-sorting" is that it ALWAYS
works if I either execute the line by stepping through the code, or if I run
a little stand-alone macro that executes the sorting macro.

How can this possibly be please? Regards, Brett



All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com