Eine Familie von Microsoft-Tabellenkalkulationsprogrammen mit Tools zum Analysieren, Darstellen und Vermitteln von Daten.
Mein Funktionsaufruf ist:
sverweisplus(vSuchen As Variant, vArea As Range, vSpalte As Long, Optional vSeparator As Variant)
Dann schreib Dir eine UDF und rufe Sie als Formel auf:
=sverweisplus(D2;A:B;2;"#")
Andreas.
Option Explicit
Function sverweisplus(vSuchen As Variant, vArea As Range, vSpalte As Long, _
Optional vSeparator As Variant)
Dim All As Range, R As Range
Set All = FindAll(vArea.Columns(1), vSuchen, SearchFormat:=True)
If All Is Nothing Then
sverweisplus = CVErr(xlErrNA)
Else
For Each R In All
Set R = Intersect(vArea.Columns(vSpalte), R.EntireRow)
sverweisplus = sverweisplus & R.Value & vSeparator
Next
sverweisplus = Left(sverweisplus, Len(sverweisplus) - Len(vSeparator))
End If
End Function
Function FindAll(ByVal Where As Range, ByVal What, _
Optional ByVal After As Variant, _
Optional ByVal LookIn As XlFindLookIn = xlValues, _
Optional ByVal LookAt As XlLookAt = xlWhole, _
Optional ByVal SearchOrder As XlSearchOrder = xlByRows, _
Optional ByVal SearchDirection As XlSearchDirection = xlNext, _
Optional ByVal MatchCase As Boolean = False, _
Optional ByVal SearchFormat As Boolean = False) As Range
'Find all occurrences of What in Where (Windows version)
Dim FirstAddress As String
Dim C As Range
'From FastUnion:
Dim Stack As New Collection
Dim Temp() As Range, Item
Dim i As Long, j As Long
If Where Is Nothing Then Exit Function
If SearchDirection = xlNext And IsMissing(After) Then
'Set After to the last cell in Where to return the first cell in Where in front if _
it match What
Set C = Where.Areas(Where.Areas.Count)
'BUG in XL2010: Cells.Count produces a RTE 6 if C is the whole sheet
'Set After = C.Cells(C.Cells.Count)
Set After = C.Cells(C.Rows.Count * CDec(C.Columns.Count))
End If
Set C = Where.Find(What, After, LookIn, LookAt, SearchOrder, _
SearchDirection, MatchCase, SearchFormat:=SearchFormat)
If C Is Nothing Then Exit Function
FirstAddress = C.Address
Do
Stack.Add C
If SearchFormat Then
'If you call this function from an UDF and _
you find only the first cell use this instead
Set C = Where.Find(What, C, LookIn, LookAt, SearchOrder, _
SearchDirection, MatchCase, SearchFormat:=SearchFormat)
Else
If SearchDirection = xlNext Then
Set C = Where.FindNext(C)
Else
Set C = Where.FindPrevious(C)
End If
End If
'Can happen if we have merged cells
If C Is Nothing Then Exit Do
Loop Until FirstAddress = C.Address
'FastUnion algorithm © Andreas Killer, 2011:
'Get all cells as fragments
ReDim Temp(0 To Stack.Count - 1)
i = 0
For Each Item In Stack
Set Temp(i) = Item
i = i + 1
Next
'Combine each fragment with the next one
j = 1
Do
For i = 0 To UBound(Temp) - j Step j * 2
Set Temp(i) = Union(Temp(i), Temp(i + j))
Next
j = j * 2
Loop Until j > UBound(Temp)
'At this point we have all cells in the first fragment
Set FindAll = Temp(0)
End Function