Skip to content

Instantly share code, notes, and snippets.

@tomfleet
Last active May 16, 2024 00:49
Show Gist options
  • Select an option

  • Save tomfleet/53c18a1ae8a69ed8c4dcec6cd460c871 to your computer and use it in GitHub Desktop.

Select an option

Save tomfleet/53c18a1ae8a69ed8c4dcec6cd460c871 to your computer and use it in GitHub Desktop.
Colour your excel cell backgrounds based on values.
Public Function myRGB(r, g, b)
Dim clr As Long, src As Range, sht As String, f, v
If IsEmpty(r) Or IsEmpty(g) Or IsEmpty(b) Then
clr = vbWhite
Else
clr = RGB(r, g, b)
End If
Set src = Application.ThisCell
sht = src.Parent.Name
f = "Changeit(""" & sht & """,""" & _
src.Address(False, False) & """," & clr & ")"
src.Parent.Evaluate f
myRGB = ""
End Function
Sub ChangeIt(sht, c, clr As Long)
ThisWorkbook.Sheets(sht).Range(c).Interior.Color = clr
End Sub
@tomfleet
Copy link
Author

I throw this in an excel workbook VB module, then just "=myRGB(uin8_t r, uint8_t g, uint8_t b)" in a cell.
ex

  • =myRGB(255,128,0) -> orange
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment