In de onderstaande code wordt 8 x dezelfde routine herhaald, telkens voor een ander blad, met een andere voorwaarde.
Kan die code verkort worden tot 1 routine?
Bekijk bijlage Antje.xlsm
Kan die code verkort worden tot 1 routine?
Bekijk bijlage Antje.xlsm
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
With Sheets("Dag1")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("A:A").SpecialCells(2)
If cl.Value = "1" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Dag2")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("A:A").SpecialCells(2)
If cl.Value = "2" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Dag3")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("A:A").SpecialCells(2)
If cl.Value = "3" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Dag4")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("A:A").SpecialCells(2)
If cl.Value = "4" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Leiding")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("B:B").SpecialCells(2)
If cl.Value = "leiding" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Catering")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("B:B").SpecialCells(2)
If cl.Value = "catering" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Huisvesting")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("B:B").SpecialCells(2)
If cl.Value = "huisvesting" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
With Sheets("Communicatie")
.Range("A5:N" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).ClearContents
For Each cl In Sheets("Totaal").Range("B:B").SpecialCells(2)
If cl.Value = "communicatie" Then
cl.EntireRow.Copy .Cells(.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1)
End If
Next
End With
Application.ScreenUpdating = True
End Sub