Hi,
0
implies that the sheet can't be found. This could be caused by all sorts of things.
Another problem is that if a codename is updated in the VBE, the function will not update because the codenames aren't in the function's argument list. I think the best you can hope for is making it volatile. I've also corrected a few other things which could cause a problem in a UDF:
Code:
Option Explicit
Public Function GetSheetName(ByVal cName As String) As Variant
Const NOTFOUND As String = "Not Found"
Dim wks As Worksheet
Application.Volatile
On Error GoTo Errorhandler
GetSheetName = NOTFOUND
For Each wks In ThisWorkbook.Worksheets
If UCase$(wks.codeName) = UCase$(cName) Then
GetSheetName = wks.Name
Exit For
End If
Next
ErrorExit:
Exit Function
Errorhandler:
GetSheetName = CVErr(xlErrValue)
Resume ErrorExit
End Function
Does that make any difference?
(By the way, I'm not sure why you would want to return this information to a worksheet?!)
Hope that helps...