Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Hangs reliably when executing an UDF

I created a UDF to perform a regression on two ranges, X and Y that
reliably hangs Excel 2003 and 2007: both ranges are copied into arrays
of length N, and I create an array of intermediate results of length
N*(N-1)/2 as follows

Public Function TheilSenRegression(x As Range, y As Range)
Dim xx() As Double, yy() As Double, slopes() As Double
'compute N and Nc2 = N(N-1)/2
ReDim xx(1 to N) as double 'copy x into xx
ReDim yy(1 to N) as double 'copy y into yy
ReDim slopes(1 to Nc2) as double 'copy intermediate results into
slopes
..
..
TheilSenSlope = Application.WorksheetFunction.Median(slopes)

TheilSenRegression = Array(TheilSenSlope, TheilSenIntercept)

End Function


The function works like a charm when I call it less than about 10
times in a spreadsheet - X and Y are of length 100, so that nC2 is
just under 5000. Call it more often and Excel hangs reliably. My gut
instinct is that Excel gets into trouble allocating memory for the
array slope() or that calling Median causes a problem, but have no
thoughts on how to fix it. Any insights would be greatly appreciated

Sincerely

Thomas Philips
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Excel Hangs reliably when executing an UDF

I can't say what is causing your problem, but here are a few things to
try:

1. add an errorhandler to the function

e.g. make the first line in the function
on error goto errorhandler
and the last lines in the function
exit function
errorhandler:
msgbox "error!"


2. there appear to be some variables in the function that are grabbing
their values from somewhere else - the values aren't passed to the
function. For example, where does N come from? Pass those values to
the function (like you do x and y).

Finally, I don't understand how this function is copying the values
from the ranges into the arrays. Is part of the code missing?

David Sauder

On Mar 28, 3:34 pm, wrote:
I created a UDF to perform a regression on two ranges, X and Y that
reliably hangs Excel 2003 and 2007: both ranges are copied into arrays
of length N, and I create an array of intermediate results of length
N*(N-1)/2 as follows

Public Function TheilSenRegression(x As Range, y As Range)
Dim xx() As Double, yy() As Double, slopes() As Double
'compute N and Nc2 = N(N-1)/2
ReDim xx(1 to N) as double 'copy x into xx
ReDim yy(1 to N) as double 'copy y into yy
ReDim slopes(1 to Nc2) as double 'copy intermediate results into
slopes
.
.
TheilSenSlope = Application.WorksheetFunction.Median(slopes)

TheilSenRegression = Array(TheilSenSlope, TheilSenIntercept)

End Function

The function works like a charm when I call it less than about 10
times in a spreadsheet - X and Y are of length 100, so that nC2 is
just under 5000. Call it more often and Excel hangs reliably. My gut
instinct is that Excel gets into trouble allocating memory for the
array slope() or that calling Median causes a problem, but have no
thoughts on how to fix it. Any insights would be greatly appreciated

Sincerely

Thomas Philips


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
Excel hangs up. bc Excel Discussion (Misc queries) 0 February 28th 06 06:30 PM
autorecover doesn't work reliably during a forced reboot johndog Excel Discussion (Misc queries) 1 January 8th 06 03:17 PM
Excel Hangs Linda Excel Discussion (Misc queries) 2 October 4th 05 04:36 PM
UserForm Initialize event doesn't fire reliably RB Smissaert Excel Programming 13 February 16th 05 01:39 AM
Reliably get sheet 1 of the active workbook Michael D. Ober Excel Programming 6 October 27th 03 07:48 PM


All times are GMT +1. The time now is 03:38 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"