AW: Schade, Begründung hätte mich interessiert ...
26.08.2019 21:28:55
onur
Ganz einfach: Excel stört sich 1.)
daran, dass du negative Zahlen in Zellen versuchst zu schreiben, die als Datum formatiert sind.
Wenn du Value2 statt des 2. Value nimmst, klappt es jedoch, da Value2 alles als Zahlen nimmt.
Und 2.)
Ausserdem sollte der Rangebereich fix und nicht variabel sein:
Sub Makro3()
Dim rng
Dim loLetzte As Long, j As Long, x As Long
Application.ScreenUpdating = False
With Worksheets("Ergebnis")
loLetzte = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("B1:C1").Copy .Range("B1:C" & loLetzte)
.Range("B2:C" & loLetzte).Copy
.Range("B2:C" & loLetzte).PasteSpecial xlPasteValues
.Range("E1").Copy .Range("E2:E" & loLetzte)
.Range("E2:E" & loLetzte).Copy
.Range("E2:E" & loLetzte).PasteSpecial xlPasteValues
.Range("K1").Copy .Range("K1:K" & loLetzte)
.Range("K2:K" & loLetzte).Copy
.Range("K2:K" & loLetzte).PasteSpecial xlPasteValues
.Columns("K:K").Copy
.Columns("F:F").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
.Range("L1") = "Formel" 'Zeile 1 markieren!!
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("C1:C" & loLetzte), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=.Range("F1:F" & loLetzte), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("A1:L" & loLetzte)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Zeile der Markierung in Spalte l suchen
x = .Cells(Rows.Count, 12).End(xlUp).Row
'Formeln ggf. in Zeile1 zurück kopieren
If x > 1 Then
.Cells(x, 2).Resize(1, 2).Copy .Range("B1")
.Cells(x, 7).Resize(1, 5).Copy .Range("G1")
.Cells(x, 5).Copy .Range("E1")
.Rows(x).Value = .Rows(x).Value
End If
Set rng = .Range("G2:J" & loLetzte)
.Range("G1:J1").Copy rng
rng.Value = rng.Value2
.Cells(x, 12) = Empty 'markierung löschen
.Range("E2").Select
End With
End Sub