View Full Version : Solved: Sorting macro

06-14-2005, 02:27 PM
I am trying to use the code in this KB article http://www.vbaexpress.com/kb/getarticle.php?kb_id=479#instr . I am having trouble because I need to sort three columns - that part is ok - but what happens is that it sorts after the first cell is filled and that would be great but the user will need to fill 3 columns before I want the sort to happen. So in column A they will enter the date in this format mm/dd (month and then day, sorry if that is TMI but want to be clear) in the next column will go the client name and in the third column would be the type of activity that is happening, really just a code anywhere from 1 - 4 characters. Then I want the sort to happen. How would i modify this so that the sort happens after the 3rd column is filled in? What am I missing?

I have attached a copy of the file - I know it is ugly but I am still just learning! As always - Thanks!!

BTW - nice code mdmackillop!!! :clap:

06-14-2005, 02:34 PM
Thanks TButhe,
Which column(s) are you wanting to sort on? Only the first, or more than that?

06-14-2005, 03:01 PM
My code is not really applicable here, being more concerned with altering a range name.
Try the following, which assumes a sort on column B. The code assumes data has been entered in columns A & B and will then be triggered by a change in column C, so this may require adjustment depending upon how data etc. is inserted/changed.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then
Range("A8:AK" & Target.Row()).Select
Selection.Sort Key1:=Range("B8"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Cells(Target.Row() + 1, "A").Select
End If
End Sub

06-15-2005, 12:55 PM
That did it!!!:cloud9: :thumb :clap: It works like a charm!! I just changed it to sort on the date column and it is great. Thank you so much for taking the time to help me out. I am marking this one solved!