+ Reply to Thread
Results 1 to 3 of 3

Auto Sorting Multiple Columns - Last Row Will Not Sort

Hybrid View

  1. #1
    Registered User
    Join Date
    08-19-2013
    Location
    RGV
    MS-Off Ver
    Excel 2010
    Posts
    2

    Auto Sorting Multiple Columns - Last Row Will Not Sort

    Good Afternoon.

    I would like to call on the powers that are Excel Help Forum.
    I am currently working on a database that catalogs companies by :Company Number, Number of Employees, Address, GPS Coordinates, City/State, and Date established.

    I am attempting to make the rows Auto Sort as they are being input into the sheet, (Smallest to Largest) by company number and number of employees.
    I would like to input the entire row before it sorts. I have attached a small sample with the code I have so far, but the last row input will not sort properly. The last row entered sorts only by Company Number an not by Number of Employees. I know that using merged cells is frowned upon, however, this is an established database and people entering the data don't like change. Any help would be GREATLY appreciated. Thanks in advance.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-15-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Auto Sorting Multiple Columns - Last Row Will Not Sort

    Pls see if this meets your needs. Changed your code to a)track when changes are made to Company Number OR Number of employees b)Added an extra Sort key for Count of employees

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A20:A49")) Is Nothing Then
    Application.EnableEvents = False
    Me.Sort.SortFields.Clear

    Me.Sort.SortFields.Add Key:=Range("A20:A49"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    Me.Sort.SortFields.Add Key:=Range("C20:C49"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With Me.Sort
    .SetRange Range("A20:O49")
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Application.EnableEvents = True
    ElseIf Not Intersect(Target, Range("C20:C49")) Is Nothing Then
    Application.EnableEvents = False
    Me.Sort.SortFields.Clear
    Me.Sort.SortFields.Add Key:=Range("A20:A49"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    Me.Sort.SortFields.Add Key:=Range("C20:C49"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With Me.Sort
    .SetRange Range("A20:O49")
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Application.EnableEvents = True
    End If
    End Sub

  3. #3
    Registered User
    Join Date
    08-19-2013
    Location
    RGV
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Auto Sorting Multiple Columns - Last Row Will Not Sort

    Thanks for the help! I tweaked it a bit to sort after all the data has been entered into the row and VIOLA!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. auto sort data in one column and apply sorting to all columns
    By lmonroe in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-03-2013, 08:18 PM
  2. Sorting at two columns (Advanced Sort doesn't help)
    By shashjindal in forum Excel General
    Replies: 3
    Last Post: 12-16-2011, 02:18 AM
  3. Need auto sort macro. (3 Sorting Levels)
    By BrokenHero in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2009, 07:39 PM
  4. [SOLVED] how do i sort a complete worksheet by sorting columns
    By Martyn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-18-2006, 05:15 PM
  5. How to AUTO SORT A-Z new data in a column (not menual sorting)
    By Nir in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-08-2005, 06:35 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1