View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Math formula help (Thank you!)

"Robert Crandal" wrote:
Ultimately, the following code represents what I was looking for:

[....]
y = WorksheetFunction.Max(1, WorksheetFunction.RoundUp(x, 0))


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?

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

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

Note that VBA converts True to -1, not 1 as Excel does.

But both that expression and the WorksheetFunction.Max expression are
probably less efficient than the IIf() expression I offered previously, to
wit:

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