• 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 Rows by multi cell values or color

mjack59

New Member
Hello Every one
I hope I am asking this in the right thread. I would like to be able to auto sort each row based on the color of the last four columns of my spread sheet, If all four last cells in the row are green move row to the top.
I have attached my spreadsheet, rows 63,72,73,94,110,etc. would all be moved to the top since last four cells of each row are green.
If unable to sort by color then Column G >.05, Column H >99, Column I > .99, Column J > .24, any help would be greatly appreciated

Thank You
Mark
 

Attachments

  • TOS to EXCEL.xlsm
    274.3 KB · Views: 4
Hi ,

If I go by the conditional formatting rules you already have in the worksheet , the rules are :

Column G < 0.1 ,

Column H > 100 ,

Column I > 5 ,

Column J > 0.24

Using this , the code would be :
Code:
Public Sub SortAllGreen()
          Dim inputrange As Range
          Dim lastrow As Long
         
          lastrow = Me.Cells(Rows.Count, 1).End(xlUp).Row
         
          Range("K2:K" & lastrow).Formula = "=AND(G2 < 0.1 , H2 > 100 , I2 > 5 , J2 > 0.24)"
                     
          Set inputrange = Me.Range(Cells(2, 1), Cells(lastrow, "K"))
         
          inputrange.Sort Range("$K:$K"), xlDescending, , , , , , xlNo, , , xlSortColumns, xlPinYin, xlSortNormal
         
          Range("K2:K" & lastrow).ClearContents
End Sub
I have assumed that column K is not used , and can be used as a helper column. If this is not the case , then the code will have to be modified.

Narayan
 
Hello Naraya

The code above works slicker than a greased pig at the country fair.
Exactly what the doctor ordered
Thank you very much
Mark
 
Back
Top