View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
HotRod HotRod is offline
external usenet poster
 
Posts: 147
Default How to prevent Worksheet_Change loop?

OK. I've tried to do a four column SORT with the theory that excel uses a
persistent sort but it doesn't seem to work. What I did was actually sort by
the Quarter first and then by the Actual Date. (I actually added some false
dates to Quarter 4 to see if it would rise to the top and prove that the
code was not working) This is what I used below.

Any ideas on how to make excel keep the sort persistent? Do I need to
highlight the range first?

Debug.Print My_Column_Sort(First_Row, True, "A")
Debug.Print My_Column_Sort(First_Row, True, "E", "B", "C")



Function My_Column_Sort(First_Data_Row As Integer, AscendingOrder As
Boolean, _
First_Column As String, Optional Second_Column As
String = "Z", _
Optional Third_Column As String = "Z")

Range("A" & First_Data_Row & ":AA55550").Sort
Key1:=Range(First_Column & First_Data_Row), _
Order1:=xlAscending, Key2:=Range(Second_Column & First_Data_Row), _
Order2:=xlAscending, Key3:=Range(Third_Column & First_Data_Row), _
Order3:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

End Function