Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ActiveCell.DisplayFormat.Interior.Color
- ActiveCell.Interior.ColorIndex - one of 56 preset colors
- ActiveCell.Interior.Color - RGB color, used like that:
- ActiveCell.Interior.Color = RGB(255,255,255)
- Range.DisplayFormat.Interior.ColorIndex
- Range.Interior.ColorIndex
- Public Function iColor(rng As Range, Optional formatType As String) As Variant
- 'formatType: Hex for #RRGGBB, RGB for (R, G, B) and IDX for VBA Color Index
- Dim colorVal As Variant
- colorVal = rng.DisplayFormat.Interior.Color
- Select Case UCase(formatType)
- Case "HEX"
- iColor = "#" & Hex(colorVal Mod 256) & Hex((colorVal 256) Mod 256) & Hex((colorVal 65536))
- Case "RGB"
- iColor = (colorVal Mod 256) & ", " & ((colorVal 256) Mod 256) & ", " & (colorVal 65536)
- Case "IDX"
- iColor = rng.Interior.ColorIndex
- Case Else
- iColor = colorVal
- End Select
- End Function
- 'Example use of the iColor function to get the background color of selected cells
- Sub Get_Background_Color_Selection_Cells()
- Dim rng As Range
- For Each rng In Selection.Cells
- myCell.Offset(0, 1).Value = iColor(rng, "HEX")
- myCell.Offset(0, 2).Value = iColor(rng, "RGB")
- Next
- End Sub
Add Comment
Please, Sign In to add comment