Function to return a string

Grant22

New Member
Joined
Dec 28, 2016
Messages
48
Hello all, I am trying to write a function that returns a manager’s name based on the name in a column. So if column F has “John Doe” or “Jane Doe” it will return a different value based on who their manager is. But I keep getting a blank return when I enter the info. Can someone please see what I amdoing wrong? Any help is greatly appreciated!

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Public Function Manager(ManagerName As String) As String[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]Select Case UCase(ManagerName)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]
Case "John Doe","Joe Doe"[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]        Manager = "Sally Sue"[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]Case "Jane Doe" , “Dan Doe”[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]        Manager = "Mary Smith"[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]End Select[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]
End Function
[/COLOR][/SIZE][/FONT]
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Your using UCase, but none of the options are upper case, so it can't find them, try
Code:
Public Function Manager(ManagerName As String) As String

Select Case LCase(ManagerName)

Case "john doe", "joe doe"

        Manager = "Sally Sue"

Case "jane doe", "dan doe"

        Manager = "Mary Smith"

End Select

End Function
 
Upvote 0
Thanks very much for the response that worked but I'm not sure why. When the value is passed on from the cell to the function it's in proper case so why wouldn't it work in Ucase or Lcase? I guess I don't fully understand the difference. Thanks!
 
Upvote 0
UCase converts the value to uppercase, so John Doe becomes JOHN DOE. Therefore the select case won't find a match as none of the values to match were in upper case.
 
Upvote 0
Oh ok thanks for the info. Is there a version that accepts it in proper case? Like PCase for example?
 
Upvote 0
Not in VBA. You can use the worksheet function, but there is no need if the code I supplied worked.
 
Upvote 0
If you want proper case in VBA use StrConv(expression, vbProperCase)
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top