VBA Calculation mystery

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

VBA Calculation mystery

Post by ErikJan »

Maybe I'm getting to old for this... This is my immediate Window in the Excel 2010 VBE. Three numbers: P1=31.53, P2=31.46, P3=31.39
I take the average from P1 and P3 (see above): 31.46 (makes sense).
Then I subtract P2 to get... zero....

P1, P2, P3 are defined as Double. If I define "Av13_2_Dist" as Double too and calculate this:

Av13_2_Dist = Abs((P1 + P3) / 2 - P2)

The outcome is still zero. This always worked fine when I used ranges as input to P1, P2 and P3. Now I move them into a (variant) array first... could that be the cause here? And what can I do about this then? Copy the Variant array into a Double array first?? (the array has to be variant to be able to 'receive' a range)
2013-02-13 13_20_38-Microsoft Visual Basic for Applications - Data Spike Remover _ Standalone testin.png
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA Calculation mystery

Post by HansV »

Er, what is the problem exactly?
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: VBA Calculation mystery

Post by ErikJan »

Deeper than I thought... my brain's not working. Looks like an error in my algorithm and not in Excel I think. I'll re-check and if you don't hear back... ignore me :grin: