LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Precision in Excle VBA

Hi. I may be wrong, but it appears to me that:

asstdrop(i) = (asstdrop(i) * 1000 + (acttdrop - asstdrop(i)) * 0.5 *
1000) / 1000


is equal to:
asstdrop(i) = (asstdrop(i) + acttdrop)/2

--
HTH. :)
Dana DeLouis
Windows XP, Office 2003


"duane" wrote in
message ...

Here is my entire code. It currently recurses the assumed to actual to
within 1.2 on an actual of -51.5, and generally to within 0.1 on
actuals closer to zero. I put the recursionlimit in because at one
point the macro would not stop recursing - I never figured out why so I
simply limited it. Increasing the limit does not improve the results.
On about 120 rows of data, it runs in about 2 seconds.

Option Explicit
Sub Temprecurse()
Dim acttdrop As Double
Dim asstdrop(200) As Double
Dim lastrow As Integer
Dim firstrow As Integer
Dim asstemplosscol As Integer
Dim acttemplosscol As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim terror As Double
firstrow = Range("b5").Row
lastrow = Range("b5").End(xlDown).Row
asstemplosscol = Range("asssegtloss").Column
acttemplosscol = Range("segtloss").Column
j = asstemplosscol
k = acttemplosscol
' initialize assumed temperature drops to 4 f
For i = firstrow To lastrow
Cells(i, j).Value = 4
Next i
' Begin recursion routine
i = firstrow - 1
nextrow:
l = 0
i = i + 1
' quit after last row
If i lastrow Then GoTo done
'Read in assumed and actual temperature drops
asstdrop(i) = Cells(i, j).Value
acttdrop = Cells(i, k).Value
recurse:
l = l + 1
'Calculate error of assumed vs actual
terror = Abs(asstdrop(i) * 1000 - acttdrop * 1000)
' set tolerance for assumed vs actual
If terror < 1 Then GoTo nextrow
' split the difference on assumed vs actual for new estimate
asstdrop(i) = (asstdrop(i) * 1000 + (acttdrop - asstdrop(i)) * 0.5 *
1000) / 1000
'limit recursion to 500 tries
If l = 500 Then GoTo nextrow Else GoTo recurse
done:
For i = 5 To lastrow
Cells(i, j).Value = asstdrop(i)
Next i
End Sub


--
duane


------------------------------------------------------------------------
duane's Profile:
http://www.excelforum.com/member.php...o&userid=11624
View this thread: http://www.excelforum.com/showthread...hreadid=561671



 
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
Help with Excle Formula Dave Eade Excel Discussion (Misc queries) 11 August 29th 08 04:08 PM
Excle 2003 Amit Kulkarni Excel Discussion (Misc queries) 5 April 26th 08 01:22 PM
average in excle [email protected] Excel Worksheet Functions 10 July 16th 07 11:57 PM
help in excle setting neelkamalgupta New Users to Excel 1 February 13th 06 08:57 PM
Precision displayed does not match precision in cell James Wilkerson Excel Discussion (Misc queries) 10 June 15th 05 02:40 PM


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