Ik wil graag een lus krijgen voor de volgende code. Als een bepaalde cel de waarde heeft 'In dienst'dan moet hij een regel kopieren naar een apart werkblad. In de onderstaande code duurt het erg lang voordat de code is uitgevoerd, deze code komt namelijk 20 keer onder elkaar voor. Weet iemand hoe dit sneller kan mbv bijv. een lus?
Code:
If Sheets("Blad4").Range("B3") = "In dienst" Then
iSchrijfRij = Sheets("Blad2").Range("A502").End(xlUp).Row + 1
Sheets("Blad1").Range("B7:H7").Copy
Sheets("Blad2").Activate
Sheets("Blad2").Rows(iSchrijfRij).PasteSpecial xlValues
Sheets("Blad2").Range("A8:H502").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Application.GoTo Sheets("Blad2").Range("A1"), True
Worksheets("Blad2").Range("A8:H502").Select
Selection.Sort Key1:=Worksheets("Blad2").Range("A8"), Order1:=xlAscending, Key2:=Worksheets("Blad2").Range("B8"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End If
If Sheets("Blad4").Range("B4") = "In dienst" Then
iSchrijfRij = Sheets("Blad3").Range("A502").End(xlUp).Row + 1
Sheets("Blad1").Range("B8:H8").Copy
Sheets("Blad3").Activate
Sheets("Blad3").Rows(iSchrijfRij).PasteSpecial xlValues
Sheets("Blad3").Range("A8:H502").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Application.GoTo Sheets("Blad3").Range("A1"), True
Worksheets("Blad3").Range("A8:H502").Select
Selection.Sort Key1:=Worksheets("Blad3").Range("A8"), Order1:=xlAscending, Key2:=Worksheets("Blad3").Range("B8"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End If