Gruppe
Allgemein
Problem
Die Zahlen aus der Tabelle sollen rechts daneben so sortiert werden, dass sie jeweils nur in einer Zeile erscheinen und dort in der Spalte, in der sie in der Quelltabelle vorhanden sind.
StandardModule: Modul1
Sub MySort()
Dim rngSource As Range, rngTarget As Range, rng As Range, rngFind As Range
Dim iCol As Integer, iRow As Integer
Set rngSource = Range("A1").CurrentRegion
iCol = rngSource.Columns.Count
Set rngTarget = Range(Cells(1, iCol + 2), Cells(65536, iCol * 2 + 1))
For Each rng In rngSource.Cells
Set rngFind = rngTarget.Find(rng.Value, LookIn:=xlValues, lookat:=xlWhole)
If rngFind Is Nothing Then
iRow = iRow + 1
rngTarget(iRow, rng.Column).Value = rng.Value
Else
rngTarget(rngFind.Row, rng.Column).Value = rng.Value
End If
Next rng
End Sub