Zellen "merge" - sehr langsam
Klaus
Hallo Freunde,
ich habe ein Makro um Zellen zu verbinden. Ansich läuft es gut und stabil, jedoch braucht es unheimlich Zeit.
Ich möchte mit 2 If-Abfragen Zellen pro Spalte verbinden, jeweils in den Spalten von A bis U.
Das Problem ist, das es sich hier meist um mehr als 2000 Zeilen handelt, das macht es sehr langsam.
Anbei mein Code. Hat jemand eine Idee, wie man das schneller hinbekommt?
Vielen Dank schon im voraus.
Dim i As Long
Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
a = Cells(i, 2).Value
If Cells(i - 1, 2).Value = a Then
a = Cells(i, 1).Value
If Cells(i - 1, 1).Value = a Then
Range(Cells(i - 1, 1), Cells(i, 1)).Merge
End If
a = Cells(i, 2).Value
If Cells(i - 1, 2).Value = a Then
Range(Cells(i - 1, 2), Cells(i, 2)).Merge
End If
a = Cells(i, 3).Value
If Cells(i - 1, 3).Value = a Then
Range(Cells(i - 1, 3), Cells(i, 3)).Merge
End If
a = Cells(i, 4).Value
If Cells(i - 1, 4).Value = a Then
Range(Cells(i - 1, 4), Cells(i, 4)).Merge
End If
a = Cells(i, 5).Value
If Cells(i - 1, 5).Value = a Then
Range(Cells(i - 1, 5), Cells(i, 5)).Merge
End If
a = Cells(i, 6).Value
If Cells(i - 1, 6).Value = a Then
Range(Cells(i - 1, 6), Cells(i, 6)).Merge
End If
a = Cells(i, 7).Value
If Cells(i - 1, 7).Value = a Then
Range(Cells(i - 1, 7), Cells(i, 7)).Merge
End If
a = Cells(i, 8).Value
If Cells(i - 1, 8).Value = a Then
Range(Cells(i - 1, 8), Cells(i, 8)).Merge
End If
a = Cells(i, 9).Value
If Cells(i - 1, 9).Value = a Then
Range(Cells(i - 1, 9), Cells(i, 9)).Merge
End If
a = Cells(i, 10).Value
If Cells(i - 1, 10).Value = a Then
Range(Cells(i - 1, 10), Cells(i, 10)).Merge
End If
a = Cells(i, 11).Value
If Cells(i - 1, 11).Value = a Then
Range(Cells(i - 1, 11), Cells(i, 11)).Merge
End If
a = Cells(i, 12).Value
If Cells(i - 1, 12).Value = a Then
Range(Cells(i - 1, 12), Cells(i, 12)).Merge
End If
a = Cells(i, 13).Value
If Cells(i - 1, 13).Value = a Then
Range(Cells(i - 1, 13), Cells(i, 13)).Merge
End If
a = Cells(i, 14).Value
If Cells(i - 1, 14).Value = a Then
Range(Cells(i - 1, 14), Cells(i, 14)).Merge
End If
a = Cells(i, 15).Value
If Cells(i - 1, 15).Value = a Then
Range(Cells(i - 1, 15), Cells(i, 15)).Merge
End If
a = Cells(i, 16).Value
If Cells(i - 1, 16).Value = a Then
Range(Cells(i - 1, 16), Cells(i, 16)).Merge
End If
a = Cells(i, 17).Value
If Cells(i - 1, 17).Value = a Then
Range(Cells(i - 1, 17), Cells(i, 17)).Merge
End If
a = Cells(i, 18).Value
If Cells(i - 1, 18).Value = a Then
Range(Cells(i - 1, 18), Cells(i, 18)).Merge
End If
a = Cells(i, 19).Value
If Cells(i - 1, 19).Value = a Then
Range(Cells(i - 1, 19), Cells(i, 19)).Merge
End If
a = Cells(i, 20).Value
If Cells(i - 1, 20).Value = a Then
Range(Cells(i - 1, 20), Cells(i, 20)).Merge
End If
a = Cells(i, 21).Value
If Cells(i - 1, 21).Value = a Then
Range(Cells(i - 1, 21), Cells(i, 21)).Merge
End If
a = Cells(i, 22).Value
If Cells(i - 1, 22).Value = a Then
Range(Cells(i - 1, 22), Cells(i, 22)).Merge
End If
End If
Next i