Sub Afschrijving()
Dim iSRij As Integer, iRij As Integer
Application.StatusBar = "Ik ben bezig - even geduld."
If MsgBox("Eerst met ASAP nagaan of er in kolom G & H & J en L geen formules zijn, enkel die kolommen selecteren met ASAP", _
vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
MsgBox ("Nagaan dat alle subtotalen als bereik één cel boven het laatste getal hebben")
MsgBox ("Anders gaat de macro crashen want de formule verwijst dan naar een cel die gewist is geweest")
iRij = Range("A65536").End(xlUp).Row
For iSRij = iRij To 4 Step -1
If Cells(iSRij, "J").HasFormula = False And Cells(iSRij, "M") <> "" Then
Cells(iSRij, "J").Value = Cells(iSRij, "M").Value
End If
If Cells(iSRij, "H").HasFormula = False And Cells(iSRij, "H").Value >= 1 And Cells(iSRij, "I").Value < 1 Then
Rows(iSRij).Select
Selection.Delete Shift:=xlUp
ElseIf Cells(iSRij, "H").HasFormula = False And Cells(iSRij, "H").Value > 1 Then
Cells(iSRij, "F").Value = Cells(iSRij, "F").Value - Cells(iSRij, "H").Value
Cells(iSRij, "H").Value = 0
End If
If Cells(iSRij, "E") = 100 Then
Cells(iSRij, "K").Value = 0
End If
If Cells(iSRij, "K").HasFormula = False And Cells(iSRij, "L").Value < 1 And Cells(iSRij, "M") <> "" And _
Cells(iSRij, "E") <> 100 Then
Cells(iSRij, "L").Value = ""
Cells(iSRij, "K").Offset(-1).Copy Destination:=Cells(iSRij, "k")
End If
If Cells(iSRij, "F").HasFormula = False And Cells(iSRij, "G") <> "" Then
Cells(iSRij, "F").Value = Cells(iSRij, "G").Value
Cells(iSRij, "G").Value = ""
End If
If Cells(iSRij, "F").HasFormula = False And Cells(iSRij, "H") < 0 Then
Cells(iSRij, "F").Value = Cells(iSRij, "I").Value
Cells(iSRij, "H").Value = ""
End If
Next
Range("F2").Value = DateSerial(Year(Now()) - 1, 12, 31)
Range("J2").Value = DateSerial(Year(Now()) - 1, 12, 31)
Range("I2").Value = DateSerial(Year(Now()), 12, 31)
Range("M2").Value = DateSerial(Year(Now()), 12, 31)
Application.StatusBar = "Klaar"
End If
MsgBox ("Ook eens nagaan of in kolom K overal een formule staat!")
End Sub