VBA - How to check if a String is a valid hex color code?
<p>To prevent errors, I need to check if a String retrieved from a custom input box is not a valid hex color code. So far I found various solutions for other languages, but none for VBA.</p>

<p>Working on the following code, giving a not hex value input will cause a run time error. That's critical to my project, since I am working on a protected sheet.</p>

<pre><code>Public Function HexWindow(MyCell As String, Description As String, Caption As String)
    Dim myValue As Variant
    Dim priorValue As Variant
    priorValue = Range(MyCell).Value
    myValue = InputBox(Description, Caption, Range(MyCell).Value)
    Range(MyCell).Value = myValue
    If myValue = Empty Then
        Range(MyCell).Value = priorValue
    End If
    tHex = Mid(Range(MyCell).Text, 6, 2) &amp; Mid(Range(MyCell).Text, 4, 2) &amp; Mid(Range(MyCell).Text, 2, 2)
    Range(MyCell).Interior.Color = WorksheetFunction.Hex2Dec(tHex)
End Function
</code></pre>

<p>How can I set a condition that recognizes a value not being in the format of "#" &amp; 6 characters from 0-9 and A-F in any case?</p>