VB Code:
Sub flexvalue()
Dim j As Double
Dim k As Double
Dim iSheet As Worksheet
Dim nSheet As Worksheet
Dim rSheet As Worksheet
Dim nkSheet As Worksheet
Set iSheet = ActiveWorkbook.Sheets("Input")
Set nSheet = ActiveWorkbook.Sheets("Nedskrivning-Lån")
Set rSheet = ActiveWorkbook.Sheets("Resultater")
Set nkSheet = ActiveWorkbook.Sheets("Nedskrivning-Kredit")
Application.ScreenUpdating = False
nSheet.Activate
For j = 2 To 10000
nSheet.Cells(20, 16).Value = iSheet.Cells(j, 16).Value
iSheet.Activate
If iSheet.Range(Cells(j, 16), Cells(j, 16)).Value > 0 Then
iSheet.Range(Cells(j, 1), Cells(j, 1)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 1), Cells(j, 1)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 3), Cells(j, 5)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 2), Cells(j, 4)).PasteSpecial Paste:=xlValues
If iSheet.Cells(j, 15).Value = "Lån" Then
iSheet.Activate
iSheet.Range(Cells(j, 17), Cells(j, 17)).Copy
nSheet.Activate
nSheet.Range(Cells(14, 2), Cells(14, 2)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 3), Cells(j, 3)).Copy
nSheet.Activate
nSheet.Range(Cells(20, 6), Cells(20, 6)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 5), Cells(j, 5)).Copy
nSheet.Activate
nSheet.Range(Cells(20, 3), Cells(20, 3)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 21), Cells(j, 30)).Copy
nSheet.Activate
nSheet.Range("$B$20:$B$29").PasteSpecial Transpose:=True, Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 31), Cells(j, 40)).Copy
nSheet.Activate
nSheet.Range("$B$35:$B$44").PasteSpecial Transpose:=True, Paste:=xlValues
nSheet.Range(Cells(20, 10), Cells(29, 10)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 5), Cells(j, 5)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nSheet.Activate
nSheet.Range(Cells(35, 10), Cells(44, 10)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 15), Cells(j, 15)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nSheet.Activate
nSheet.Range(Cells(31, 12), Cells(31, 12)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 25), Cells(j, 25)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nSheet.Activate
nSheet.Range(Cells(46, 12), Cells(46, 12)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 26), Cells(j, 26)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nSheet.Activate
nSheet.Range(Cells(48, 12), Cells(48, 12)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 27), Cells(j, 27)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nSheet.Activate
nSheet.Range(Cells(48, 12), Cells(48, 12)).Copy
iSheet.Activate
iSheet.Range(Cells(j, 41), Cells(j, 41)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False
Else
iSheet.Activate
iSheet.Range(Cells(j, 17), Cells(j, 17)).Copy
nkSheet.Activate
nkSheet.Range(Cells(8, 2), Cells(8, 2)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 3), Cells(j, 3)).Copy
nkSheet.Activate
nkSheet.Range(Cells(14, 6), Cells(14, 6)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 5), Cells(j, 5)).Copy
nkSheet.Activate
nkSheet.Range(Cells(14, 3), Cells(14, 3)).PasteSpecial Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 21), Cells(j, 23)).Copy
nkSheet.Activate
nkSheet.Range("$B$14:$B$16").PasteSpecial Transpose:=True, Paste:=xlValues
iSheet.Activate
iSheet.Range(Cells(j, 31), Cells(j, 33)).Copy
nkSheet.Activate
nkSheet.Range("$B$22:$B$24").PasteSpecial Transpose:=True, Paste:=xlValues
nkSheet.Range(Cells(14, 10), Cells(16, 10)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 5), Cells(j, 5)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nkSheet.Activate
nkSheet.Range(Cells(22, 10), Cells(24, 10)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 15), Cells(j, 15)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nkSheet.Activate
nkSheet.Range(Cells(18, 12), Cells(18, 12)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 25), Cells(j, 25)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nkSheet.Activate
nkSheet.Range(Cells(26, 12), Cells(26, 12)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 26), Cells(j, 26)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nkSheet.Activate
nkSheet.Range(Cells(28, 12), Cells(28, 12)).Copy
rSheet.Activate
rSheet.Range(Cells(j, 27), Cells(j, 27)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False, Transpose:=True
nkSheet.Activate
nkSheet.Range(Cells(28, 12), Cells(28, 12)).Copy
iSheet.Activate
iSheet.Range(Cells(j, 41), Cells(j, 41)).PasteSpecial Paste:=xlValues, operation:=xlNone, skipblanks:=False
End If
End If
Next j
Application.CutCopyMode = False
Set iSheet = Nothing
Set nSheet = Nothing
Set rSheet = Nothing
Set nkSheet = Nothing
Application.ScreenUpdating = True
End Sub