Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA, min/max ... or other mathematical functions

Tags:

vba

I googled a lot, but I want to be sure:

Do I really need to use "Application.WorksheetFunction.Max" for the max-Function?

If yes, can I shorten this? Is there an overhead if I warp this long construct into a function?

Edit: I have removed the vba-access tag.

like image 421
testo Avatar asked Dec 03 '22 19:12

testo


1 Answers

After I see that my question was unclear, I answer it by myself.

Some people did not know if I mean EXCEL or ACCESS. My fault to give the wrong tag. It was meant as a pure VBA question.

Second mistake: I was providing a EXCEL-way (Worksheet) for my question. But it was meant as pure VBA question.

I can not delete the question, but I like to do that.

So the answer is:

Public Function max(x, y As Variant) As Variant
  max = IIf(x > y, x, y)
End Function

Public Function min(x, y As Variant) As Variant
   min = IIf(x < y, x, y)
End Function

... is doing the job.

Sorry for wasting our time!

like image 112
testo Avatar answered Dec 13 '22 21:12

testo