ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing a string to a function instead of a cell reference (https://www.excelbanter.com/excel-programming/440152-passing-string-function-instead-cell-reference.html)

rbennu

Passing a string to a function instead of a cell reference
 
Currently using excel2003 with the following UDF

Function EmpName(nam3 As String)
Select Case nam3
Case "John"
EmpName = "First"
Case "Doe"
EmpName = "Last"
End Select
End Function

This works if I use a cell reference i.e. A1=John, =EmpName(A1) but fails if
I use =EmpName(John). I can get both forms to work if I am passing a number
and evalualting the case as a number. How do i get it to use =EmpName(John)?

Thank you in advance

Joe User[_2_]

Passing a string to a function instead of a cell reference
 
"rbennu" wrote:
How do i get it to use =EmpName(John)?


=EmpName("John")

just you use strings in any Excel formula.


----- original messages -----



"rbennu" wrote:
Currently using excel2003 with the following UDF

Function EmpName(nam3 As String)
Select Case nam3
Case "John"
EmpName = "First"
Case "Doe"
EmpName = "Last"
End Select
End Function

This works if I use a cell reference i.e. A1=John, =EmpName(A1) but fails if
I use =EmpName(John). I can get both forms to work if I am passing a number
and evalualting the case as a number. How do i get it to use =EmpName(John)?

Thank you in advance


rbennu

Passing a string to a function instead of a cell reference
 
Much Thanks!

"Joe User" wrote:

"rbennu" wrote:
How do i get it to use =EmpName(John)?


=EmpName("John")

just you use strings in any Excel formula.


----- original messages -----



"rbennu" wrote:
Currently using excel2003 with the following UDF

Function EmpName(nam3 As String)
Select Case nam3
Case "John"
EmpName = "First"
Case "Doe"
EmpName = "Last"
End Select
End Function

This works if I use a cell reference i.e. A1=John, =EmpName(A1) but fails if
I use =EmpName(John). I can get both forms to work if I am passing a number
and evalualting the case as a number. How do i get it to use =EmpName(John)?

Thank you in advance



All times are GMT +1. The time now is 10:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com