Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default UDF becomes #NAME - with test case

Post the code, not an attachment.

--

HTH

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

"TY" wrote in message
...
The problem is when updating the source value of an UDF's argument will
result in #NAME.

1. Open test#NAME.xla
2. Open test#NAMEwkbk.xls in automatic calculation mode
3. Change the cell A4 to "blah"
4. Notice UDF in B4 is changed to #NAME, which is expected to be 100.5

Anyone knows why?

Thanks.

Teresa






  #2   Report Post  
Posted to microsoft.public.excel.programming
TY TY is offline
external usenet poster
 
Posts: 5
Default UDF becomes #NAME - with test case

Ok, the addin has a few modules.
The test case will be:
1. Open test#NAME.xla
2. Create a new file
3. In cell A1, enter s1
cell A2, enter s2
cell B1, enter '=foo(A1,A2)
4. The value in B1 is 10.5
5. Save the workbook and close
6. Now open the saved workbook again
7. In cell A1, change the content to "blah"
4. Notice the value in B1 is changed to #NAME, it is expected to be 100.5

eventHandler - Class module
======================
Option Explicit
Public WithEvents appevent As Application


Private Sub appevent_NewWorkbook(ByVal Wb As Workbook)
AddK4XLreference Wb
End Sub

Private Sub appevent_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI
As Boolean, Cancel As Boolean)
RemoveK4XLreference Wb
End Sub

Private Sub appevent_WorkbookOpen(ByVal Wb As Workbook)
AddK4XLreference Wb
End Sub



functions - Standard module
=====================

Option Explicit
Option Private Module

Private hEvents As New eventHandler

Sub Auto_Open()
Set hEvents.appevent = Application
End Sub

Public Sub AddK4XLreference(Wb As Workbook)
Dim i As Integer
Dim found As Boolean

If (Wb.FullName < ThisWorkbook.FullName) Then
found = False
For i = 1 To Wb.VBProject.References.Count
If Wb.VBProject.References.Item(i).Name = "TY" Then
found = True
Exit For
End If
Next i

If (Not found) Then
Wb.VBProject.References.AddFromFile ThisWorkbook.FullName
End If

End If

End Sub


Public Sub RemoveK4XLreference(Wb As Workbook)
Dim i As Integer
Dim found As Boolean

If (Wb.FullName < ThisWorkbook.FullName) Then
found = False

'Add the reference if it doesn't already exist
For i = 1 To Wb.VBProject.References.Count
If Wb.VBProject.References.Item(i).Name = "TY" Then
found = True
Exit For
End If
Next i

If found Then
Wb.VBProject.References.Remove Wb.VBProject.References.Item(i)
End If

End If
End Sub

Function FOO(Optional s1 As String, Optional s2 As String)
If (s1 = "s1") Then
FOO = 10.5
Else
FOO = 100.5
End If

End Function


"Bob Phillips" wrote in message
...
Post the code, not an attachment.

--

HTH

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

"TY" wrote in message
...
The problem is when updating the source value of an UDF's argument will
result in #NAME.

1. Open test#NAME.xla
2. Open test#NAMEwkbk.xls in automatic calculation mode
3. Change the cell A4 to "blah"
4. Notice UDF in B4 is changed to #NAME, which is expected to be 100.5

Anyone knows why?

Thanks.

Teresa








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
test for upper case MusicMan Excel Worksheet Functions 6 July 7th 09 10:10 AM
change data of entire column from small case to upper case Ann Excel Worksheet Functions 1 August 16th 08 01:06 PM
Changing multiple cell text from lower case to upper case Patti Excel Discussion (Misc queries) 2 January 4th 08 08:35 PM
Defaulting test to Upper case Skippy Excel Worksheet Functions 3 September 13th 07 04:17 PM
Change the text from lower case to upper case in an Excel work boo dave01968 Excel Discussion (Misc queries) 2 December 9th 05 09:09 AM


All times are GMT +1. The time now is 04:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"