• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sort colours

Derek McGill

Active Member
Any code to sort this by highest Red colour and ties by lowest Green, So that it looks like bottom ?
 

Attachments

  • Resluts.xlsx
    13.7 KB · Views: 3
Don't understand the rest.
Code:
Sub test()
    Dim myCol As Long
    myCol = Rows(1).Find("Total Games").Column
    With Intersect(Columns(1).SpecialCells(2).Areas(1).EntireRow, Columns(1).Resize(, myCol).EntireColumn)
        .Offset(-1).Resize(.Rows.Count + 1).Copy .Offset(.Rows.Count + 4)
        With .Offset(.Rows.Count + 4).CurrentRegion.Resize(, myCol)
            .Columns(.Columns.Count).Replace ChrW(189), ".5", 2
            .Sort .Cells(1, .Columns.Count), 2, , , , , , 1
            .Columns(.Columns.Count).Replace ".5", ChrW(189), 2
            Union(.Columns(1), .Columns(.Columns.Count)).Copy .Columns(.Columns.Count + 3)
            With .Columns(.Columns.Count + 2)
                With .Offset(1).Resize(.Rows.Count - 1)
                    .Value = Evaluate("row(1:" & .Rows.Count & ")")
                    .CurrentRegion.Borders.Weight = 2
                    .CurrentRegion.BorderAround Weight:=4
                    .Columns(3).NumberFormat = "#.0"
                End With
            End With
        End With
    End With
End Sub
 

Attachments

  • Resluts with code.xlsm
    24.6 KB · Views: 2
Change to
Code:
Sub test()
    Dim myCol As Long
    myCol = Rows(2).Find("#Red").Column
    With Intersect(Columns(1).SpecialCells(2).Areas(1).EntireRow, Columns(1).Resize(, myCol).EntireColumn)
        .Offset(-1).Resize(.Rows.Count + 1).Copy .Offset(.Rows.Count + 4)
        With .Offset(.Rows.Count + 4).CurrentRegion.Resize(, myCol)
            .Sort .Cells(1, .Columns.Count - 1), 2, , .Cells(1, .Columns.Count), 1, , , 1
            .Columns(.Columns.Count - 1).Resize(, 2).Clear
            Union(.Columns(1), .Columns(.Columns.Count - 2)).Copy .Columns(.Columns.Count + 1)
            With .Columns(.Columns.Count)
                With .Offset(1).Resize(.Rows.Count - 1)
                    .Value = Evaluate("row(1:" & .Rows.Count & ")")
                    .CurrentRegion.Borders.Weight = 2
                    .CurrentRegion.BorderAround Weight:=4
                    .Columns(3).NumberFormat = "#.0"
                End With
            End With
        End With
    End With
End Sub
 
It looks like it only sorts 1 col and has no VBA (that i can see )

The site is called "VBA Express". all the code is there with full explanation of how to use, where to put the code, how to test....every thing!!!!


has no VBA


You need to see an optometrists.
 
See the attached.
Code:
Sub test()
    Dim myCol As Long
    myCol = Rows(2).Find("#Red").Column
    Application.DisplayAlerts = False  '<-----
    With Intersect(Columns(1).SpecialCells(2).Areas(1).EntireRow, Columns(1).Resize(, myCol).EntireColumn)
        .Offset(-1).Resize(.Rows.Count + 1).Copy .Offset(.Rows.Count + 4)
        Application.DisplayAlerts = True  '<-----
        With .Offset(.Rows.Count + 4).CurrentRegion.Resize(, myCol)
            .Sort .Cells(1, .Columns.Count - 1), 2, , .Cells(1, .Columns.Count), 1, , , 1
            ........
 

Attachments

  • Resluts with code.xlsm
    24.6 KB · Views: 4
Back
Top