Row\Col | A | B | C | D | E |
1 | RGB | 128 | 128 | 0 | B1:D1: Input |
2 | HSL | 40 | 60 | 240 | B2:D2: {=RGBToHLS(B1,C1,D1)} |
3 | RGB | 128 | 128 | 0 | B3:D3: {=HLsToRGB(B2,C2,D2)} |
' Color conversions revised 2009-11, 2015-0105
Public Declare Function ColorRGBToHLS Lib "shlwapi.dll" _
(ByVal clrRGB As Long, _
pwHue As Long, _
pwLuminance As Long, _
pwSaturation As Long) As Long
Public Declare Function ColorHLSToRGB Lib "shlwapi.dll" _
(ByVal wHue As Long, _
ByVal wLuminance As Long, _
ByVal wSaturation As Long) As Long
Function RGBToHLS(iRed As Long, iGrn As Long, iBlu As Long) As Variant
' shg 2014
' wrapper for ColorRGBToHLS
Dim iHue As Long
Dim iLum As Long
Dim iSat As Long
ColorRGBToHLS RGB(iRed, iGrn, iBlu), iHue, iLum, iSat
RGBToHLS = Array(iHue, iLum, iSat)
End Function
Function HLSToRGB(iHue As Long, iLum As Long, iSat As Long) As Variant
' shg 2014
' wrapper for ColorHLSToRGB
Dim iRGB As Long
iRGB = ColorHLSToRGB(iHue, iLum, iSat)
HLSToRGB = Array(iRGB And 255, (iRGB \ 256) And 255, (iRGB \ 65536) And 255)
End Function
Private Sub FormatCells()
Dim rA As Range
Dim rB As Range
Set rA = Range("C1")
Set rB = Range("D4")
AddColoredBorders Union(rA, rB), HLSToRGB(0, 128, 150)
End Sub
Sub AddColoredBorders(myRange As Range, iColor() As Variant)
With myRange.Borders
.LineStyle = xlContinuous
.Color = RGB(iColor(0), iColor(1), iColor(2))
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
Dim i As Integer
For i = 0 to 100
HLSToRGB(AlternateHues(CLng(i)), 128, 150)
Next i
Function AlternateHues(iHue As Long)
If iHue Mod 2 = 0 Then
If iHue > 255 Then
AlternateHues = iHue - 255
Else
AlternateHues = HLSToRGB(iHue)
End If
Else
If iHue > 255 Then
AlternateHues = iHue + 85 - 255
Else
AlternateHues = HLSToRGB(iHue + 85)
End If
End If
End Function