简体   繁体   中英

Function in VBA does not work in excel

So I am trying to write a function that takes two arguments (strings) and adds them together.

If I try to call this function using subroutine as you can see in the code below, everything works and a message box with the two strings shows.

However, when I go to excel spreadsheet and enter the function into a cell like this: =add_strings("doesnt", "work") or =add_strings(doesnt, work) , it doesnt work and displays value error instead.

However, when I define a function with only single argument - then it works. So if I put one string as the function argument and the define another string inside of the function and then return the strings appended, it works. But when I have more arguments, excel kind of struggles to accept them. Any ideas? thank you

Function add_strings(a As String, b As String) As String
add_strings = a & b
End Function

Sub caller()
Dim strVar As String
strVar = add_strings("doesnt", "work")
MsgBox strVar
End Sub

问题已解决-参数分隔符的确不是逗号,而是半冒号(;)。

I tried the function in excel 2013 and it works fine without any errors

Check the attached screenshot

https://i.stack.imgur.com/n0WHW.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM