color difference
DESCRIPTION
using excel,v lookup,h lookupTRANSCRIPT
Sheet1Color SampleColor Difference ScoreBrightness Difference ScoreVerdictThis is sample text 123456789765255AcceptableThis is sample text 123456789765255AcceptableThis is sample text 123456789561208AcceptableThis is sample text 123456789638211AcceptableThis is sample text 1234567893831No GoodThis is sample text 123456789510134AcceptableThis is sample text 123456789510154AcceptableThis is sample text 12345678920461No GoodThis is sample text 12345678940835No GoodThis is sample text 123456789408167No GoodThis is sample text 12345678925523No GoodThis is sample text 123456789561179AcceptableThis is sample text 123456789458196No GoodThis is sample text 12345678925690No GoodThis is sample text 12345678925537No GoodThis is sample text 123456789637240AcceptableThis is sample text 123456789230102No GoodThis is sample text 1234567893069No GoodThis is sample text 12345678912838No GoodThis is sample text 1234567891531No GoodThis is sample text 12345678930659No GoodThis is sample text 123456789357136No GoodThis is sample text 123456789612213Acceptable
Attribute VB_Name = "Module1"Option Explicit
Function ColorDifference(cell As Range)' Returns a color difference score from 0 to 765 Dim bg As Variant, fg As Variant Dim maxRed As Long, minRed As Long Dim maxGreen As Long, minGreen As Long Dim maxBlue As Long, minBlue As Long bg = DECIMAL2RGB(cell.Interior.Color) fg = DECIMAL2RGB(cell.Font.Color) maxRed = Application.Max(bg(0), fg(0)) minRed = Application.Min(bg(0), fg(0)) maxGreen = Application.Max(bg(1), fg(1)) minGreen = Application.Min(bg(1), fg(1)) maxBlue = Application.Max(bg(2), fg(2)) minBlue = Application.Min(bg(2), fg(2)) ColorDifference = (maxRed - minRed) + (maxGreen - minGreen) + (maxBlue - minBlue)End Function
Function BrightnessDifference(cell As Range)' Returns a brightness difference score from 0 to 255 Dim bg As Variant, fg As Variant Dim bgBright As Double, fgBright As Double bg = DECIMAL2RGB(cell.Interior.Color) fg = DECIMAL2RGB(cell.Font.Color) bgBright = ((bg(0) * 299) + (bg(1) * 587) + (bg(2) * 114)) / 1000 fgBright = ((fg(0) * 299) + (fg(1) * 587) + (fg(2) * 114)) / 1000 BrightnessDifference = Abs(bgBright - fgBright)End Function
Function DECIMAL2RGB(ColorVal) As Variant' Converts a color value to an RGB triplet' Returns a 3-element variant array DECIMAL2RGB = Array(ColorVal \ 256 ^ 0 And 255, ColorVal \ _ 256 ^ 1 And 255, ColorVal \ 256 ^ 2 And 255)End Function
Attribute VB_Name = "Sheet1"Attribute VB_Base = "0{00020820-0000-0000-C000-000000000046}"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = TrueAttribute VB_TemplateDerived = FalseAttribute VB_Customizable = True
Attribute VB_Name = "ThisWorkbook"Attribute VB_Base = "0{00020819-0000-0000-C000-000000000046}"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = TrueAttribute VB_TemplateDerived = FalseAttribute VB_Customizable = True