Access/VBA Library


Returns the largest value in a set of values.


Max( args-1 [, args-2 [,...[, args-N]]] )
Name Type Description
args Variant Required. Values for which you want to determine the largest value. Arguments of type Object are ignored.
Return value

Variant : The largest value of the given set of values.

Public Function Max(ParamArray args())
    Dim MaxValue
    Dim Index As Long
    MaxValue = Empty
    For Index = LBound(args) To UBound(args)
        If Not IsMissing(args(Index)) Then
            If Not IsObject(args(Index)) Then
                If args(Index) > MaxValue Then MaxValue = args(Index)
            End If
        End If
    Next Index
    Max = MaxValue
End Function


  • It's wise to make sure the arguments are of the same type.
  ' Comparing numeric values
  MsgBox Max(1, 4, 6.1, 5, -3, 4, 6)
  ' Will result in : 6.1
  ' Comparing strings
  Msgbox Max("ABC", "Just a string", "Whatever", "what's new?")
  ' Will result in : what's new?
  ' Comparing dates
  MsgBox Max(Date, Now(), DateAdd("m", 1, Date))
  ' Will result in the value of the @DateAdd funtion