Gruppe
UDF
Problem
Die benutzerdefinierte Funktion B4 prüft, ob in Blatt "Adressen" sowohl der Name wie auch die PLZ übereinstimmen und liefert den zutreffenden Ort.
StandardModule: Modul1
Function GetAddress(sName As String, Optional sPlz As String)
Dim lRow As Long
Dim iCount As Integer
iCount = WorksheetFunction.CountIf(Worksheets("Adressen").Columns(1), sName)
lRow = 1
With Worksheets("Adressen")
Do Until IsEmpty(.Cells(lRow, 1))
If iCount > 1 Then
If .Cells(lRow, 1).Value = sName And _
.Cells(lRow, 2).Value = sPlz Then
GetAddress = .Cells(lRow, 3).Value
Exit Function
End If
Else
If .Cells(lRow, 1).Value = sName Then
GetAddress = .Cells(lRow, 3).Value
Exit Function
End If
End If
lRow = lRow + 1
Loop
End With
GetAddress = ""
End Function