Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Faster For-Next Loop?

In the function below I have a For-Next loop that loops though a range
of cells. Would it be any faster to read the range into an array and
loop through the array?

Function InvDistanceWtd(x, y, xdata as Range, ydata as Range, zdata as
Range, power)
N = Application.Count(xdata)
For i = 1 To N
D = Sqr((x - xdata(i, 1)) ^ 2 + (y - ydata(i, 1)) ^ 2)
SumZoDn = SumZoDn + data(i, 1) / D ^ Power
SumIDn = SumIDn + 1 / D ^ Power
Next i
InvDistanceWtd = SumZoDn / SumIDn
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Faster For-Next Loop?

Depending on the size of your range, but in general: a LOT faster!
The arrays in my functions are generally 120 elements (actuarial tables);
difference in the order of 10 times faster.

wrote in message
oups.com...
In the function below I have a For-Next loop that loops though a range
of cells. Would it be any faster to read the range into an array and
loop through the array?

Function InvDistanceWtd(x, y, xdata as Range, ydata as Range, zdata as
Range, power)
N = Application.Count(xdata)
For i = 1 To N
D = Sqr((x - xdata(i, 1)) ^ 2 + (y - ydata(i, 1)) ^ 2)
SumZoDn = SumZoDn + data(i, 1) / D ^ Power
SumIDn = SumIDn + 1 / D ^ Power
Next i
InvDistanceWtd = SumZoDn / SumIDn
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Faster For-Next Loop?

Hello. You pass "zdata" to your function, but I don't see it used. Is
there a typo?

--
Dana DeLouis
Win XP & Office 2003


wrote in message
oups.com...
In the function below I have a For-Next loop that loops though a range
of cells. Would it be any faster to read the range into an array and
loop through the array?

Function InvDistanceWtd(x, y, xdata as Range, ydata as Range, zdata as
Range, power)
N = Application.Count(xdata)
For i = 1 To N
D = Sqr((x - xdata(i, 1)) ^ 2 + (y - ydata(i, 1)) ^ 2)
SumZoDn = SumZoDn + data(i, 1) / D ^ Power
SumIDn = SumIDn + 1 / D ^ Power
Next i
InvDistanceWtd = SumZoDn / SumIDn
End Function



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Faster For-Next Loop?

Yes, I was in the process of renaming the range variable data (used in
line 5) to zdata.

Dana DeLouis wrote:
Hello. You pass "zdata" to your function, but I don't see it used.

Is
there a typo?

--
Dana DeLouis
Win XP & Office 2003


wrote in message
oups.com...
In the function below I have a For-Next loop that loops though a

range
of cells. Would it be any faster to read the range into an array

and
loop through the array?

Function InvDistanceWtd(x, y, xdata as Range, ydata as Range, zdata

as
Range, power)
N = Application.Count(xdata)
For i = 1 To N
D = Sqr((x - xdata(i, 1)) ^ 2 + (y - ydata(i, 1)) ^ 2)
SumZoDn = SumZoDn + data(i, 1) / D ^ Power
SumIDn = SumIDn + 1 / D ^ Power
Next i
InvDistanceWtd = SumZoDn / SumIDn
End Function


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
can this be done faster? Frank Excel Discussion (Misc queries) 7 August 9th 07 10:02 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
Is there a faster way Jim May Excel Programming 3 September 19th 04 04:42 AM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM
Which one is faster? Syed Zeeshan Haider[_4_] Excel Programming 14 December 4th 03 05:28 PM


All times are GMT +1. The time now is 09:55 AM.

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

About Us

"It's about Microsoft Excel"