Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 02-09-2014, 02:38 PM
Kreol2013 Kreol2013 is offline Is it possible to sort cells in shades of colors? Windows 7 32bit Is it possible to sort cells in shades of colors? Office 2013
Novice
Is it possible to sort cells in shades of colors?
 
Join Date: Apr 2013
Posts: 8
Kreol2013 is on a distinguished road
Wink

Hi!
Yes, eventually I stopped on the circuit HSV
Hue sorting ascending
Value sorting ascending
Sat sorting descending
Thank you

sample code:
Code:
Sub test()
    For i = 2 To 5000
        sHexVal = Cells(i, 5).Value
        If (sHexVal <> "") Then
Call RGBtoHSV(Cells(i, 6).Value, Cells(i, 7).Value, Cells(i, 8).Value, i)
        End If
    Next i
End Sub

Sub RGBtoHSV(Red, Green, Blue, y)
    Dim min As Double, max As Double, delta As Double
    If Red <= Green And Red <= Blue Then min = Red
    If Green <= Red And Green <= Blue Then min = Green
    If Blue <= Red And Blue <= Green Then min = Blue
    
    If Red >= Green And Red >= Blue Then max = Red
    If Green >= Red And Green >= Blue Then max = Green
    If Blue >= Red And Blue >= Green Then max = Blue
    
    Value = max
    delta = max - min
    
    If Not delta = 0 Then
        Sat = delta / max
    Else
        Sat = 0
        Hue = 0
        Cells(y, 9).Value = Sat
        Cells(y, 10).Value = Hue
        Cells(y, 11).Value = Value
        Exit Sub
    End If
    
    If Red = max Then
        Hue = (Green - Blue) / delta
    ElseIf Green = max Then
        Hue = 2 + (Blue - Red)
    Else
        Hue = 4 + (Red - Green) / delta
    End If
    Hue = Hue * 60
    If Hue < 0 Then Hue = Hue + 360
        Cells(y, 9).Value = Sat
        Cells(y, 10).Value = Hue
        Cells(y, 11).Value = Value
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to sort cells in shades of colors? How to Sort Table Cells from Left to Right tamaracklodge Word Tables 4 03-04-2013 04:00 AM
Is it possible to sort cells in shades of colors? Unable to change font colors from theme colors choy Word 3 08-01-2012 09:12 PM
Is it possible to sort cells in shades of colors? Auto Colors in Cells? Learner7 Excel 5 07-06-2010 10:55 PM
How can I change the colors of cells automatically based on Job Completion? Learner7 Excel 0 07-06-2010 10:47 PM
Count range cells eliminating merge cells danbenedek Excel 0 06-15-2010 12:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft