Ich nage an einem eigentlich einfachen Problem und stehe wahrscheinlich nur auf dem Schlauch.
In einer einfachen Tabelle soll, wenn in der Spalte A der Begriff "Über-/Unterdeckung" auftaucht, ein Zeilenumbruch eingefügt werden.
Ein Makro läuft die Zellen (beginnend mit der 12.) durch und prüft, ob die Der Begriff in der Zelle steht. Wenn ja, macht es ein paar Formatierungen und fügt den Zeilenumbruch nach der Zelle ein.
Das Problem ist, dass ich immer 2 Zeilenumbrüche bekomme, einen an der richtigen Stelle und einen eine Zeile darüber. Wo ist der Fehler ?`
Hier das Makro:
With ActiveSheet
s = 12
Do Until s = 300
If Cells(s, 1).Value = "Über-/Unterdeckung" Then
'Formatierung
Range(Cells(12, 1), Cells(s, 3)).Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'Zeilenumbruch einfügen
Cells(s + 1, 1).Select
ActiveSheet.HPageBreaks.Add Before:=Cells(s + 1, 1)
Exit Do
End If
s = s + 1
Loop
Vielen Dank für Eure Hilfe im voraus !