Discussion Locked

max and min

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I thought there were functions max and min in VBA, as in Algol, Fortran, Cobol. But I get an error message at compilation, and have been reduced to defining them myself. Help is no help. The functions I want have this kind of definition
Def max(x,y): if x>y then x else y fi
Are these things really in VBA and if so how do I access them?

5 replies

by chimp

There is no Max function, amazingly. You can do it using an Excel worksheet function or Access SQL. VBScript functions are even more limited, see the following:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexpvb/html/usingvbscriptfunctions.asp

by john_wills

The url does not work - I did take the blanks out of it and, via a text editor, get it all on one line.

by gaston nusimovich

You can insert a module in the VBA environment and define your own functions, and the use you own functions as if they were VBA functions, like this

Function MyMax(x As Double, y As Double) As Double

Dim retval As Double

If x > y Then
retval = x

Else

retval = y

End If

MyMax = retval

End Function

Good luck !

by john_wills

This is the kind of thing I have been doing myself, except that I did not have the intermediate variable retval.

This discussion is closed to new replies.