View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Call to custom function appears as typed not as result

David,

In the workbook that shows formulas, goto menu ToolsOptions and on the View
tab, look to see if the Formulas box (left hand of the Windows Options
section) is checked. If so, clear it down.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"David Bernheim" wrote in message
...
I placed the same custom function in a module in 2 workbooks, using
identical code, where it is the only contents of the VBA module. One works
fine, the other does not! Instead of displaying the resulting value I get
the text I typed in to call the function.

My function is AddCC(). The call AddCC("A,B","C") should show the result
"A/C,B/C".
In one workbook this is OK, in the other the cell displays
'AddCC("A,B","C")', with the formula showing as '=AddCC("A,B","C")'

Have I missed an option somewhere. Any other ideas, as I am beat!

CODE
-------
Option Explicit

Option Base 1 ' All arrays to start at 1, not 0

Function AddCC(szAccount As String, szCC As String)

Dim szNewString As String 'Work string to return

Dim i As Integer 'Counter

szAccount = Trim(szAccount)

'Return account + CC if there is only one

If InStr(szAccount, ",") = 0 Then

AddCC = szAccount & "/" & szCC

Exit Function

End If

For i = 1 To Len(szAccount)

If Mid(szAccount, i, 1) < "," Then

'Add next char if not a comma

szNewString = szNewString & Mid(szAccount, i, 1)

Else

'Char is a comma, so add CC

szNewString = szNewString & "/" & szCC & ","

End If

Next

If Right(szAccount, 1) < "," Then

szNewString = szNewString & "/" & szCC

End If

AddCC = szNewString

End Function