+ Reply to Thread
Results 1 to 6 of 6

Auto Sort Overrides Color Sort

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2018
    Location
    Edmonton, AB
    MS-Off Ver
    Excel 2013
    Posts
    4

    Wink Auto Sort Overrides Color Sort

    I'm making a database for excel. The goal is to have the data input into it Auto sort by color and then Alphabetically.

    I'm using the following VBA to auto sort.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        On Error Resume Next
        If Not Intersect(Target, Range("A:A")) Is Nothing Then
            Range("A1").Sort Key1:=Range("A2"), _
              Order1:=xlAscending, Header:=xlYes, _
              OrderCustom:=1, MatchCase:=False, _
              Orientation:=xlTopToBottom
    
        End If
    
    End Sub
    And I've set up Macros for the color sorting as follows:

    With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
        ActiveWorkbook.Worksheets("Master").ListObjects("Table2").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Master").ListObjects("Table2").Sort.SortFields.Add( _
            Range("Table2[Name]"), xlSortOnCellColor, xlDescending, , xlSortNormal). _
            SortOnValue.Color = RGB(255, 0, 0)
        With ActiveWorkbook.Worksheets("Master").ListObjects("Table2").Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End Sub
    The problem is once I input new data, the alphabetical sort overrides the color sort.

    Can someone please help me make it so that the color sorting overrides the alphabetical?

    Any help is greatly appreciated!
    Last edited by AngXen; 04-17-2018 at 01:44 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Auto Sort Overrides Color Sort

    Just add a call to the color sort after the auto sort:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    On Error Resume Next
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Range("A1").Sort Key1:=Range("A2"), _
    Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom
    
    End If
    Call Colorsort
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    04-16-2018
    Location
    Edmonton, AB
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Auto Sort Overrides Color Sort

    Quote Originally Posted by xladept View Post
    Just add a call to the color sort after the auto sort:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    On Error Resume Next
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Range("A1").Sort Key1:=Range("A2"), _
    Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom
    
    End If
    Call Colorsort
    End Sub
    This didn't work for me

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Auto Sort Overrides Color Sort

    Welcome to the Forum, AngXen,

    Thank you for adding Code Tags.

    Regards.
    Last edited by Winon; 04-17-2018 at 02:32 PM. Reason: Code Tags are added
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Auto Sort Overrides Color Sort

    Hello AngXen,

    xladept is usually spot on.

    Could you please attach a sample workbook.

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    That will enable us to better assist you.

    Regards.

  6. #6
    Registered User
    Join Date
    04-16-2018
    Location
    Edmonton, AB
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Auto Sort Overrides Color Sort

    I've attached the file and just made a note of what I want to happen on it.
    I appreciate any help you can offer
    Attached Files Attached Files

+ 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 by Color
    By indhrui in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2016, 02:52 AM
  2. Auto Sort line items based off of cell color
    By Jscott1601 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-15-2013, 11:43 AM
  3. Auto Sort line items based off of cell color
    By Jscott1601 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2013, 03:03 PM
  4. Auto Sort, Auto Lock, Auto Date & Time Stamp
    By suehatesyou in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2010, 02:57 PM
  5. Can I "auto-sort" or use a quick button to sort?
    By drewkloc71 in forum Excel General
    Replies: 4
    Last Post: 09-07-2009, 03:14 AM
  6. [SOLVED] Sort or sub-total by Fill color or font color
    By Excel_seek_help in forum Excel General
    Replies: 1
    Last Post: 04-27-2006, 04:10 PM
  7. Excel sort by Fill Color by custom list sort
    By Dash4Cash in forum Excel General
    Replies: 2
    Last Post: 07-29-2005, 06:05 PM

Tags for this Thread

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