View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal[_3_] Robert Crandal[_3_] is offline
external usenet poster
 
Posts: 161
Default Math formula help (Thank you!)

"joeu2004" wrote

Even though I offered up that solution, I'm curious: why do you want
something of that form instead of using IIf() or even If-Then-Else?


I guess I thought a math-only formula would be more concise, elegant,
and efficient than if-else programming logic. Either approach would
have worked fine, but I guess I was just being picky. Thanks for
your solution, by the way.


BTW, arguably, a purely "math" form might be:

y = -(x<=0) - (x0)*WorksheetFunction.Roundup(x,0)


Hmm, but doesn't this code involve a little bit of if-else logic because
it's comparing X with 0, and returns True or False depending on
the value of X? I know there is no direct if-else VBA code here,
but doesn't this get converted to if-else instructions at the
assembly language level?


y = IIf(x<=0,1,WorksheetFunction.Roundup(x,0))

And all are probably less efficient than:

If x0 Then y = WorksheetFunction.Roundup(x,0) Else y = 1


So, the last example of code is the most efficient solution?
Even more efficient than the code that I chose to use:
y = WorksheetFunction.Max(1, WorksheetFunction.RoundUp(x, 0)) ??