セル内で数式として使用され、問題が発生したように見える関数の作成を練習しています。以下のコードは、セルで使用されているときに文字列を返さない限り機能します。このコードは整数に対して完全に機能し、関数を使用するようにサブをコード化した場合は文字列に対しても機能します。セルの数式で使用すると、なぜ返されるのか理解できないようです。
Function bIsBlank(x As String) As String
Dim y As String
If x = "" Then 'check to see if it is blank
Exit Function
Else
y = Evaluate(x) 'solve the formula that is pulled in
If y = "0" Then 'check to see if formula equals zero
y = "" 'set to nothing if it is zero
End If
End If
'below is my attempt to fix it by adding quotes on either side of the string
'this did not work
y = Chr(34) & y & Chr(34)
'this seems to solve for a sub but not a formula in a cell for strings
bIsBlank = y
End Function
問題は、evaluate関数を使用する必要がなかったことです。私が引き込んでいた式はすでに解決されています。つまり、「A」を解決するvlookupがあったとします。コードX="A"では、当初の予想どおり、文字列vlookup(a1、a5:b10,2,0)ではありません。