Search code examples
vbaexcelstring-concatenationudf

Can't write string in a cell from UDF


Sub Makro()

    Dim a As String
    Dim b As String

    Cells(1, 1).Value = myfunction(X, X)

    If Range("A1") = "XX" Then

        MsgBox "True"
    Else

        MsgBox "False"

    End If

End Sub

Function myfunction(a, b) As String

    myfunction = a + b

End Function

"A1" cell value equals 0. It must be XX.


Solution

  • You are sending X to myfunction it should be "X". VBA is interpreting the X as a variable not a string

    Cells(1, 1).Value = myfunction("X", "X")