1

I have a data set from which I have used conditional formatting in excel to colour code values from 0 to 100 using RGB colours 0, 176, 240 (0, low) to 255, 255, 255 (50, midway point) to 255, 0, 0 (100, high). I want to pull this RGB information so that I can dsiplay the same data in another program.

I found this module script (below) to read the RGB value of a cell, however I am having the issue that each cell is reading as white (255, 255, 255) even though most cells sit either at the low or the high end of the spectrum.

I think this must be because the cells are conditionally formatted rather than set as a difinitive colour. So, is there a way I can modify the script to read the conditional formatting RGB colour, even some sort of a work around?

Function getColor(Rng As Range, ByVal ColorFormat As String) As Variant
    Dim ColorValue As Variant
    ColorValue = Cells(Rng.Row, Rng.Column).Interior.Color
    Select Case LCase(ColorFormat) 
        Case "index"
            getColor = Rng.Interior.ColorIndex
        Case "rgb"
            getColor = (ColorValue Mod 256) & ", " & ((ColorValue \\ 256) Mod 256) & ", " & (ColorValue \\ 65536)  
        Case Else
            getColor = "Only use 'Index' or 'RGB' as second argument!" 
    End Select
End Function

0 Answers0