User Tools

Site Tools


vba:functions:greatest

[VBA] greatest()

Gibt den Grössten aus einer unbestimmten Menge von Werten zurück.

Version 1.0.0 -

Beispiele

VBA

?greatest(4, 5, 13, 7)
 13 
?greatest("Hans", "Thomas", "Marcel")
Thomas

SQL

Vorsicht. Bei grossen Datenmengen könnte die Performance leiden
SELECT greatest(maturity_date, key_date, settlement_date) AS max_date
FROM tbl_my_data
 
| max_date   |
| 18.03.2015 |
| 30.09.2015 |
| 30.09.2015 |
| 30.09.2015 |
| 18.03.2015 |

Code

udf_greatest.bas
Attribute VB_Name = "udf_greatest"
'-------------------------------------------------------------------------------
'File         : udf_greatest.bas
'               Copyright mpl by ERB software
'               All rights reserved
'               http://wiki.yaslaw.info/dokuwiki/doku.php/vba/functions/greatest
'Environment  : VBA 2010 +
'Version      : 1.0.0
'Name         : strSplit
'Author       : Stefan Erb (ERS)
''-------------------------------------------------------------------------------
Option Explicit
 
'/**
' * Gibt den Grössten aus einer unbestimmten Menge von Werten zurück
' * @param  Keine Objekte
' * @return Grösster Wert
' * @example greatest("Hallo Welt", 42, "Mister-X") -> Mister-X
'*/
Public Function greatest(ParamArray iItems() As Variant) As Variant
    greatest = iItems(UBound(iItems))
    Dim item As Variant: For Each item In iItems
        If NZ(item) > NZ(greatest) Then greatest = item
    Next item
End Function
 
 
 

Discussion

Enter your comment. Wiki syntax is allowed:
If you can't read the letters on the image, download this .wav file to get them read to you.
 
vba/functions/greatest.txt · Last modified: 08.12.2015 09:06:47 by yaslaw