Change Color Based on Color Value Defined in Cell
It sounds like you want to type a hex color value into a cell and have the cell to the right change to be whatever color you typed in. That can be done with VBA. This sub is written to leave in the Sheet object although you could generalize it to work in the Workbook object if you want it to apply to all sheets.
Private Sub Worksheet_Change(ByVal Target As Range)
' Declarations
Dim watchRange As Range
Dim val As String
Dim valR As Integer, valG As Integer, valB As Integer
' Check that the target is in the range we care about
Set watchRange = Range("A1:F10")
If Not Intersect(watchRange, Target) Is Nothing Then
' Check that the cell has the right format
val = Target.Value
If Len(val) = 7 And Left(val, 1) = "#" Then
' Convert #RRGGBB to decimal RGB
valR = Application.WorksheetFunction.Hex2Dec(Mid(val, 2, 2))
valG = Application.WorksheetFunction.Hex2Dec(Mid(val, 4, 2))
valB = Application.WorksheetFunction.Hex2Dec(Mid(val, 6, 2))
' Color the cell
Target.Offset(0, 1).Interior.Color = RGB(valR, valG, valB)
End If
End If
End Sub
The part you really need to change is this bit:Set watchRange = Range("A1:F10")
That tells VBA that you only care about changing colors if the cell you changed is within that range. Without this bit, it'll trigger the event whenever you change any cell anywhere. Another key point is that will only fire when you type in a new color. Deleting the cell contents will not return the neighboring cell to no fill.
There are more clever ways to do this but I think this does a decent job and is clear in its execution.