Results 1 to 11 of 11

Sort by colour

Threaded View

  1. #1
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    OFFICE 365
    Posts
    177

    Sort by colour

    Hi,

    I have the code below that I used Macro Recorder the problem having is sorting the headers as well the data Start at cell "B14" and "B12" and "B13" are headers.

    how to modify it that:

    1. Sort but not including headers
    2. Cells that are blank no colors to be at the bottom. (attaching sample of file)

    here is the code:

    Sub sort_bycolours()
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Clear
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
     255, 0)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(146, _
     208, 80)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(112, 48 _
     , 160)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(31, 73 _
     , 125)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(204, _
     153, 0)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(192, 0 _
     , 0)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(148, _
     138, 84)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(218, _
     150, 148)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(141, _
     180, 226)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(38, 38 _
     , 38)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(217, _
     217, 217)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(252, _
     213, 180)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add(Range("B16:B55"), _
     xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(128, _
     128, 128)
     ActiveWorkbook.Worksheets("STATEMENT").Sort.SortFields.Add2 Key:=Range( _
     "B16:B55"), SortOn:=xlSortOnCellColor, Order:=xlAscending, DataOption:= _
     xlSortNormal
     With ActiveWorkbook.Worksheets("STATEMENT").Sort
     .SetRange Range("STMTRNG")'("B14").CurrentRegion
     .Header = xlNo
     .MatchCase = False
     .Orientation = xlTopToBottom
     .SortMethod = xlPinYin
     .Apply
     End With
    End Sub

    thank you,
    Attached Files Attached Files
    Last edited by 6StringJazzer; 05-13-2022 at 03:26 PM. Reason: Moved from Excel - New Users/Basics

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] sort table on colour and than on value
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2020, 04:11 AM
  2. How to Sort by Colour
    By sunplum in forum Excel General
    Replies: 1
    Last Post: 01-23-2013, 06:57 PM
  3. can i sort rows by colour?
    By nickymac in forum Excel General
    Replies: 4
    Last Post: 09-30-2008, 02:09 PM
  4. Sort on infill colour
    By Lewej in forum Excel General
    Replies: 3
    Last Post: 08-15-2006, 10:25 AM
  5. [SOLVED] Excel should let me sort by colour
    By kbatey25 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-09-2005, 06:34 AM
  6. [SOLVED] Sort by colour
    By Mark Fox in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-07-2005, 03:05 PM
  7. [SOLVED] sort by colour
    By Gers in forum Excel General
    Replies: 1
    Last Post: 04-01-2005, 10:06 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