title: Fill a cell with color based on it's HEX value in Excel 2013
body: <p>I have a spreadsheet with cells in the A column containing colors in their HEX format. Is it possible to fill the adjacent cell automatically with the color matching the HEX value?</p>
  
  <p>From the research done until now I understand the VBA should first convert the HEX string to it's RGB correspondent and then fill the cell color with the result.</p>
  
  <p>E.g.: if A1 contains the value "7fcac3" (or "#7fcac3" but I don't think the pound is required), the VBA should fill the adjacent B cell with RGB (127,202,195).</p>
  
  <p>Below is an example of how the VBA might look, found <a href="https://answers.yahoo.com/question/index?qid=20101112022951AAKD2TC" rel="noreferrer">(here)</a>. The problem is that I get a <em>"Compile Error: Invalid outside procedure"</em> error in Excel 2013.</p>
  
  <pre><code>For i = 1 To LastRow
  
  Sub SetHexColors()
  Dim i, LastRow
  LastRow = Range("A" &amp; Rows.Count).End(xlUp).Row
  For i = 1 To LastRow
  Cells(i, "B").Interior.Color = HEXCOL2RGB(Cells(i, "A"))
  Next
  End Sub
  
  Public Function HEXCOL2RGB(ByVal HexColor As String) As String
  Dim Red As String, Green As String, Blue As String
  HexColor = Replace(HexColor, "#", "")
  Red = Val("&amp;H" &amp; Mid(HexColor, 1, 2))
  Green = Val("&amp;H" &amp; Mid(HexColor, 3, 2))
  Blue = Val("&amp;H" &amp; Mid(HexColor, 5, 2))
  HEXCOL2RGB = RGB(Red, Green, Blue)
  End Function 
  </code></pre>
  
  <p>Many thanks,
  Mathieu</p>