Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 119
Default UDF causes #VALUE! error

I have a User Defined Function that is calculating a sum based on the
contents of other cells. It seems to work execpt that when I change a cell
the formula depends on the correct value is display momentarily then the
#VALUE! is displayed. If I hit F9, the correct value is displayed.

I suspect some problem with the calculation order of the dependencies, but
would appreciate help in figuring out what is causing the problem.

I have a second UDF that is checking the state of the Autofilter fields that
also seems to do this.

The both functions are below, incase that is needed.

Thanks,
john

Function SubTotalMatch(rngSource As Range, rngMatch As Range, rngSubTotal As
Range) As Currency
Application.Volatile
Dim cCell As Range
Dim cellIndex As Integer
Dim srcStr As String
Dim Total As Currency

Total = 0

If rngSource.Count < rngMatch.Count Or rngSource.Count < rngSubTotal.Count
Then
SubTotalMatch = 0
Exit Function
End If

For cellIndex = 1 To rngSource.Count
srcStr = rngSource.Cells(cellIndex).Value

Set cCell = rngMatch.Find(srcStr, LookIn:=xlValues)
If Not cCell Is Nothing Then
If cCell.Value < "" And cCell.Offset(0, 3).Value = "" Then
Total = Total + rngSubTotal.Cells(cellIndex).Value
End If
End If
Next cellIndex

SubTotalMatch = Total
End Function

Function MyFilters(MyRange As Range) As String
Application.Volatile
Dim i As Integer
'Debug.Print "MyFilters:" & Selection.Address & " " & MyRange.Address
MyFilters = False
With MyRange.Parent.AutoFilter
If Intersect(MyRange, .Range) Is Nothing Then Exit Function
For i = 1 To .Range.Columns.Count
With .Filters(i)
If .On Then
MyFilters = True
End If
End With
Next
End With

End Function

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default UDF causes #VALUE! error

Doc,

I seem to recall some problem with using Find within a UDF... But your UDF seems like it could be
replaced with worksheet functions easily enough: either SUMIF or SUMPRODUCT, so describe what the
functions actually does, and perhaps we can suggest a native function.

HTH,
Bernie
MS Excel MVP


"DocBrown" wrote in message
...
I have a User Defined Function that is calculating a sum based on the
contents of other cells. It seems to work execpt that when I change a cell
the formula depends on the correct value is display momentarily then the
#VALUE! is displayed. If I hit F9, the correct value is displayed.

I suspect some problem with the calculation order of the dependencies, but
would appreciate help in figuring out what is causing the problem.

I have a second UDF that is checking the state of the Autofilter fields that
also seems to do this.

The both functions are below, incase that is needed.

Thanks,
john

Function SubTotalMatch(rngSource As Range, rngMatch As Range, rngSubTotal As
Range) As Currency
Application.Volatile
Dim cCell As Range
Dim cellIndex As Integer
Dim srcStr As String
Dim Total As Currency

Total = 0

If rngSource.Count < rngMatch.Count Or rngSource.Count < rngSubTotal.Count
Then
SubTotalMatch = 0
Exit Function
End If

For cellIndex = 1 To rngSource.Count
srcStr = rngSource.Cells(cellIndex).Value

Set cCell = rngMatch.Find(srcStr, LookIn:=xlValues)
If Not cCell Is Nothing Then
If cCell.Value < "" And cCell.Offset(0, 3).Value = "" Then
Total = Total + rngSubTotal.Cells(cellIndex).Value
End If
End If
Next cellIndex

SubTotalMatch = Total
End Function

Function MyFilters(MyRange As Range) As String
Application.Volatile
Dim i As Integer
'Debug.Print "MyFilters:" & Selection.Address & " " & MyRange.Address
MyFilters = False
With MyRange.Parent.AutoFilter
If Intersect(MyRange, .Range) Is Nothing Then Exit Function
For i = 1 To .Range.Columns.Count
With .Filters(i)
If .On Then
MyFilters = True
End If
End With
Next
End With

End Function



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 119
Default UDF causes #VALUE! error

Bernie,

I would LOVE to be able to do this with a native function. The algorithm has
multiple parts. See my other post under Programming called 'Sumproduct
forumla for complex sum' (sic). (I don't know how to create a link to the
posting.)

Thanks,
john

"Bernie Deitrick" wrote:

Doc,

I seem to recall some problem with using Find within a UDF... But your UDF seems like it could be
replaced with worksheet functions easily enough: either SUMIF or SUMPRODUCT, so describe what the
functions actually does, and perhaps we can suggest a native function.

HTH,
Bernie
MS Excel MVP


"DocBrown" wrote in message
...
I have a User Defined Function that is calculating a sum based on the
contents of other cells. It seems to work execpt that when I change a cell
the formula depends on the correct value is display momentarily then the
#VALUE! is displayed. If I hit F9, the correct value is displayed.

I suspect some problem with the calculation order of the dependencies, but
would appreciate help in figuring out what is causing the problem.

I have a second UDF that is checking the state of the Autofilter fields that
also seems to do this.

The both functions are below, incase that is needed.

Thanks,
john

Function SubTotalMatch(rngSource As Range, rngMatch As Range, rngSubTotal As
Range) As Currency
Application.Volatile
Dim cCell As Range
Dim cellIndex As Integer
Dim srcStr As String
Dim Total As Currency

Total = 0

If rngSource.Count < rngMatch.Count Or rngSource.Count < rngSubTotal.Count
Then
SubTotalMatch = 0
Exit Function
End If

For cellIndex = 1 To rngSource.Count
srcStr = rngSource.Cells(cellIndex).Value

Set cCell = rngMatch.Find(srcStr, LookIn:=xlValues)
If Not cCell Is Nothing Then
If cCell.Value < "" And cCell.Offset(0, 3).Value = "" Then
Total = Total + rngSubTotal.Cells(cellIndex).Value
End If
End If
Next cellIndex

SubTotalMatch = Total
End Function

Function MyFilters(MyRange As Range) As String
Application.Volatile
Dim i As Integer
'Debug.Print "MyFilters:" & Selection.Address & " " & MyRange.Address
MyFilters = False
With MyRange.Parent.AutoFilter
If Intersect(MyRange, .Range) Is Nothing Then Exit Function
For i = 1 To .Range.Columns.Count
With .Filters(i)
If .On Then
MyFilters = True
End If
End With
Next
End With

End Function




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default UDF causes #VALUE! error

On Fri, 18 Sep 2009 00:24:01 -0700, DocBrown
wrote:

I have a User Defined Function that is calculating a sum based on the
contents of other cells. It seems to work execpt that when I change a cell
the formula depends on the correct value is display momentarily then the
#VALUE! is displayed. If I hit F9, the correct value is displayed.

I suspect some problem with the calculation order of the dependencies, but
would appreciate help in figuring out what is causing the problem.


When I run into this kind of problem, I usually wind up setting multiple break
points and/or stepping through the routine to see where it fails.
--ron
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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Error of slope taking into account error of the data points cer144 Excel Worksheet Functions 5 July 7th 08 07:26 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 08:18 PM.

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"