Consulting

Results 1 to 4 of 4

Thread: Sorting macro

  1. #1
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location

    Red face Sorting macro

    I am trying to use the code in this KB article http://www.vbaexpress.com/kb/getarti...b_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!!!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks TButhe,
    Which column(s) are you wanting to sort on? Only the first, or more than that?

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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

  4. #4
    VBAX Regular TButhe's Avatar
    Joined
    Sep 2004
    Location
    Sioux Falls, SD
    Posts
    64
    Location
    That did it!!! 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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •