quemuenchatocha
Board Regular
- Joined
- Aug 4, 2021
- Messages
- 50
- Office Version
- 365
- 2019
- Platform
- Windows
Ejemplo_1.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Color | Hexadecimal | Color Code | RGB | R | G | B | Name Color | ||
2 | #0048BA | Absolute Zero | ||||||||
3 | #B0BF1A | Acid green | ||||||||
4 | #7CB9E8 | Aero | ||||||||
5 | #C0E8D5 | Aero blue | ||||||||
6 | #B284BE | African violet | ||||||||
7 | #72A0C1 | Air superiority blue | ||||||||
8 | #EDEAE0 | Alabaster | ||||||||
9 | #F0F8FF | Alice blue | ||||||||
10 | #C46210 | Alloy orange | ||||||||
11 | #EFDECD | Almond | ||||||||
12 | #E52B50 | Amaranth | ||||||||
13 | #9F2B68 | Amaranth (M&P) | ||||||||
14 | #F19CBB | Amaranth pink | ||||||||
15 | #AB274F | Amaranth purple | ||||||||
16 | #D3212D | Amaranth red | ||||||||
17 | #3B7A57 | Amazon | ||||||||
18 | #FFBF00 | Amber | ||||||||
List Of Colors |
Dear Best regards, in search of your best advice I am trying to obtain a function that will allow me to get the color of a cell [A2:A975] from the hexadecimal values recorded in another cell [B2:B975]. So far I have only gotten the following basic lines:
VBA Code:
Sub SetHexCol()
Dim i As Integer, LastRow As Integer
LastRow = Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
Cells(i, "A").Interior.Color = HexToRgb(Cells(i, "B"))
Next
End Sub
VBA Code:
Function HexToRgb(HexColor As String) As Long
Dim R As String, G As String, B As String
HexColor = Replace(HexColor, "#", "")
R = CLng("&H" & Left(HexColor, 2))
G = CLng("&H" & Mid(HexColor, 3, 2))
B = CLng("&H" & Right(HexColor, 2))
HexToRgb = rgb(R, G, B)
End Function
My idea is that regardless of the cell where the hexadecimal value is located (not just in column B for my case), the function will allow me to fill a cell with the color resulting from the six-character string given to the function.
Thanking you for your valuable help and suggestions to obtain the desired result, I say goodbye