AW: Sehe keine Frage sondern nur eine Formel...
20.10.2017 11:33:18
Peter(silie)
Hallo,
keinen schimmer ob es so stimmt... aber hier deine Mappe mit button und weiter unten nur Code.
https://www.herber.de/bbs/user/117120.xlsm
Option Explicit
Sub a()
Dim ebenen As Dictionary
Dim ws As Worksheet
Dim lRow As Long
Dim rng As Range
Set ws = ThisWorkbook.Sheets(1)
With ws
lRow = .Cells(.Rows.Count, 2).End(xlUp).Row
Set rng = .Range(.Cells(2, 2), .Cells(lRow, 2))
Set ebenen = Create_Dictionary(rng)
If ebenen Is Nothing Then Exit Sub
AddValues ebenen, rng
End With
End Sub
Private Function Create_Dictionary(ByVal rng As Range) As Dictionary
Dim tmp As Object
Dim c As Range
Set tmp = New Dictionary
For Each c In rng
If Not tmp.Exists(c.Value) And c.Value "" Then tmp.Add c.Value, ""
Next c
Set Create_Dictionary = tmp
Set tmp = Nothing
End Function
Private Sub AddValues(ByRef dict As Dictionary, ByVal rng As Range)
Dim c As Range
Dim tmp As String
Dim sameItem As Variant
Dim i As Long
For Each c In rng
tmp = c.Offset(, 3).Value & "|"
If c.Value = sameItem Then
dict(c.Value) = tmp
Else
dict(c.Value) = dict(c.Value) & tmp
End If
sameItem = c.Value
If c.Offset(, 2).Value "" Then
For i = 0 To GetIndexByKey(dict, c.Value) - 1
c.Offset(, 4).Value = c.Offset(, 4).Value & dict(dict.Keys(i))
Next i
End If
Next c
End Sub
Private Function GetIndexByKey(ByRef dict As Object, ByVal key_ As Variant) As Long
Dim varItem As Variant
For Each varItem In dict.Keys
GetIndexByKey = GetIndexByKey + 1
If varItem = key_ Then Exit Function
Next varItem
End Function