Hex encoding and decoding of ASCII strings in VBA
I think you have an opportunity for using Application.Caller in that error-handling subroutine, and make the function behave differently when it's used as a UDF vs. when it's called from VBA code.

Instead of GoTo-jumping when there's an invalid argument to early-return an Excel error value that's only really useful when the function is used as a UDF (and confusing when it's called from VBA code), you could be raising an actual meaningful error (which would still be jumping to the DecodeError label).

First, because we're raising an error in several places, I'd make a little utility procedure:

Private Sub OnHexDecodeError(ByVal message As String)
    Err.Raise 5, "HexDecode", message
End Sub




If Not StrComp(Left$(HexString, Len(HexPrefix)), HexPrefix, vbTextCompare) = 0 Then
  OnHexDecodeError "Parameter value '" &amp; HexString &amp; "' is not in the expected format."
End If




If Len(hexRaw) Mod 2 = 1 Then
  OnHexDecodeError "Parameter value '" &amp; HexString &amp; "' is invalid."
End If




  If Not IsNumeric(hexchar) Then
    OnHexDecodeError "Hex character '" &amp; hexchar &amp; "' is not a valid hexadecimal digit."
  End If


And then the error-handling subroutine could do this:

DecodeError:
  If TypeName(Application.Caller) = "Range" Then
    'function is used as a UDF
    HexDecode = CVErr(xlErrValue)
  Else
    'function is called by other VBA code
    Err.Raise Err.Number 'rethrow
  End If


That way the calling code can handle a runtime error 5 (aka invalid procedure call or argument) with a useful description:


?HexCode("test")





And now you have a function that's just as friendly to use as a UDF as it is in plain VBA code.



This doesn't strike me as intuitive:

If Len(hexRaw) Mod 2 = 1 Then


"Is value a multiple of X" is usually written as:

If value Mod x &lt;&gt; 0 Then


That way you're not assuming what the remainder might be - of course here it's either 1 or 0, but the point is that the way the comparison is written in foo Mod bar {comparison} never has to change, regardless of what the value of bar is.