Attribute VB_Name = "udf_firstValue" '------------------------------------------------------------------------------- 'File : udf_firstValue.bas ' Copyright mpl by ERB software ' All rights reserved ' http://wiki.yaslaw.info/dokuwiki/doku.php/vba/functions/firstValue 'Environment : VBA 2010 + 'Version : 1.2.0 'Name : firstValue 'Author : Stefan Erb (ERS) 'History : 16.10.2015 Prüfung auf Nothing ergänzt. Als Null gilt jetzt Null oder Nothing ' 18.05.2016 Empty wird neu auch als Null gewertet '------------------------------------------------------------------------------- Option Explicit '/** ' * gibt den ersten Eintrag der nicht NULL ist zurück. ' * Ist sehr gut geeignet um aus Queries zuzugreiffen ' * Die Funktion funktioniert auch mit Objekten ' * @return Variant ' * @example: ' * ?firstValue(null, null,13,14, null) //Rückgabewert 13 ' */ Public Function firstValue(ParamArray itemS() As Variant) As Variant For Each firstValue In itemS If IsObject(firstValue) Then If Not firstValue Is Nothing Then Exit For Else If Not NZ(firstValue, Empty) = Empty Then Exit For End If Next End Function