View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Bob Bridges Bob Bridges is offline
external usenet poster
 
Posts: 108
Default Math and action via VBA

I don't think you can restore a previous sorting order, per se, but you can
certainly resort it so it'll be back in the previous order. Two ways:

1) If you can just sort by whatever columns it was sorted on in the first
place, that's easiest, of course. Was it perhaps sorted by title, before?

2) If the data themselves don't tell you exactly how to sort it back in the
previous order, and you need that exact order, then what you have to do is
add a temporary column before sorting it the first time. There are several
ways to do it but the simplest might be like this:

With YourSheet.Range("F1:F20")
.Formula = "=ROW()"
.Copy
.PasteSpecial Paste:=xlPasteValues
End With

(This looks more complicated than looping through F1:F20 and putting the row
number in each cell, but the latter method can be much slower if you're going
to do it to more than 20 rows or so; this is fast.)

Once you have this column you can continue with your sort on QT descending,
or whatever, and once you've done what you want you can sort on column F to
get it back in the original order, then delete that column.

--- "Adnan" wrote:
....Hre's what I did though, I added this sorting code and it looks like it
works, but the thing is now, can I restore the previous serting order?