Sub KngrOvfData()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim gSheet As Worksheet
Dim tSheet As Worksheet
Dim eSheet As Worksheet
Set gSheet = ActiveWorkbook.Worksheets("Grund")
Set tSheet = ActiveWorkbook.Worksheets("Tilrettet")
Set eSheet = ActiveWorkbook.Worksheets("Ekskl.ny-øgede og tlf")
Application.ScreenUpdating = False
For i = 5 To 250
For j = i To i + 15
For k = i To i + 15
For l = 5 To 250
For m = l To l + 15
If gSheet.Cells(i, 1).Value = "BFORR" Then
If gSheet.Cells(j, 2).Value = "Kundegrupper" Then
gSheet.Activate
gSheet.Rows(j).EntireRow.Copy
tSheet.Activate
tSheet.Rows(j).PasteSpecial
Application.CutCopyMode = False
End If
If gSheet.Cells(j, 2).Value = "Mindre Erhverv" Then
gSheet.Activate
gSheet.Rows(j).EntireRow.Copy
tSheet.Activate
tSheet.Rows(j).PasteSpecial
Application.CutCopyMode = False
If gSheet.Cells(k, 2).Value = "04 Fonde/investeringsselskaber" Then
gSheet.Activate
gSheet.Range(Cells(k, 3), Cells(k, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
If gSheet.Cells(k, 2).Value = "Ukendt" Then
gSheet.Activate
gSheet.Range(Cells(k, 3), Cells(k, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
End If
'....top code repeats a couple of times, and then gets to the "bit more advanced part".
If gSheet.Cells(i, 1).Value = "Z3684 BANKAKT BG BANK" Then
If gSheet.Cells(j, 2).Value = "Kundegrupper" Then
gSheet.Activate
gSheet.Rows(j).EntireRow.Copy
tSheet.Activate
tSheet.Rows(j).PasteSpecial
Application.CutCopyMode = False
If gSheet.Cells(l, 1).Value = "N3394 CENTRAL INKASSO BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(j, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
If gSheet.Cells(l, 1).Value = "3472 Hensættelser BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(j, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
End If
If gSheet.Cells(j, 2).Value = "Mindre Erhverv" Then
gSheet.Activate
gSheet.Rows(j).EntireRow.Copy
tSheet.Activate
tSheet.Rows(j).PasteSpecial
Application.CutCopyMode = False
If gSheet.Cells(l, 1).Value = "N3394 CENTRAL INKASSO BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(j, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
If gSheet.Cells(l, 1).Value = "3472 Hensættelser BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(j, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
If gSheet.Cells(k, 2).Value = "04 Fonde/investeringsselskaber" Then
gSheet.Activate
gSheet.Range(Cells(k, 3), Cells(k, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
If gSheet.Cells(l, 1).Value = "N3394 CENTRAL INKASSO BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(k, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
If gSheet.Cells(l, 1).Value = "3472 Hensættelser BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(k, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
End If
If gSheet.Cells(k, 2).Value = "Ukendt" Then
gSheet.Activate
gSheet.Range(Cells(k, 3), Cells(k, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
If gSheet.Cells(l, 1).Value = "N3394 CENTRAL INKASSO BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(k, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
If gSheet.Cells(l, 1).Value = "3472 Hensættelser BG" And gSheet.Cells(m, 2).Value = gSheet.Cells(k, 2).Value Then
gSheet.Activate
gSheet.Range(Cells(m, 3), Cells(m, 3).End(xlToRight)).Copy
tSheet.Activate
tSheet.Range(Cells(j, 3), Cells(j, 3).End(xlToRight)).PasteSpecial Paste:=xlValues, operation:=xlAdd
Application.CutCopyMode = False
End If
End If
End If
End If
Next m
Next l
Next k
Next j
Next i
'The code has been sharply reduced to meet the 10000 character limit - but it should contain a little bit of everything like this.
End Sub