Hi, first time poster here.
I have cobbled together a script (from other sources originally) that selects row(s) containing a tick in column E (Marlett Font 'A' character) copy this/these row(s) and paste it/them into the first empty row(s) in another sheet. The script behaves almost as expected however it is selecting the 'ticked' row and pasting it multiple times rather than just once in certain cases. I haven't truly figured out why it pastes the row more than once but how many times it does paste the row seems to depend on how many non-ticked rows there are.
FYI: I do not need the entire row (just columns B:K) and have read there are other ways to achieve what I want for example - copy as an array, assign the cells directly (which I also tried).
Any help with the error in my script would be really appreciated. A couple of lines are commented out as they were interfering with pasting anything at all at an earlier stage of debugging. There are 4 sheets that this script looks through and I have inefficiently repeated the code four times over.
I have cobbled together a script (from other sources originally) that selects row(s) containing a tick in column E (Marlett Font 'A' character) copy this/these row(s) and paste it/them into the first empty row(s) in another sheet. The script behaves almost as expected however it is selecting the 'ticked' row and pasting it multiple times rather than just once in certain cases. I haven't truly figured out why it pastes the row more than once but how many times it does paste the row seems to depend on how many non-ticked rows there are.
FYI: I do not need the entire row (just columns B:K) and have read there are other ways to achieve what I want for example - copy as an array, assign the cells directly (which I also tried).
Any help with the error in my script would be really appreciated. A couple of lines are commented out as they were interfering with pasting anything at all at an earlier stage of debugging. There are 4 sheets that this script looks through and I have inefficiently repeated the code four times over.
Code:
Sub CopyRows()
Dim matchRow, Cell, LRow As Single
ScreenUpdating = False
For Each ws In Worksheets
ws.Unprotect "rdp"
Next
With Sheets("QChecklist1")
ActiveSheet.Unprotect "rdp"
For Each Cell In ActiveSheet.Range("E8:E34")
If Cell.Value = "a" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("QAnalysisForm").Select
LRow = Range("B" & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Rows(LRow).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QChecklist1").Select
Cells(1, 1).Select
End If
Next
ActiveSheet.Protect "rdp"
End With
With Sheets("QChecklist2")
ActiveSheet.Unprotect "rdp"
For Each Cell In ActiveSheet.Range("E8:E34")
If Cell.Value = "a" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("QAnalysisForm").Select
LRow = Range("B" & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Rows(LRow).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QChecklist2").Select
Cells(1, 1).Select
End If
Next
ActiveSheet.Protect "rdp"
End With
With Sheets("QChecklist3")
ActiveSheet.Unprotect "rdp"
For Each Cell In ActiveSheet.Range("E8:E34")
If Cell.Value = "a" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("QAnalysisForm").Select
LRow = Range("B" & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Rows(LRow).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QChecklist1").Select
Cells(1, 1).Select
End If
Next
ActiveSheet.Protect "rdp"
End With
With Sheets("QChecklist4")
ActiveSheet.Unprotect "rdp"
For Each Cell In ActiveSheet.Range("E8:E34")
If Cell.Value = "a" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("QAnalysisForm").Select
LRow = Range("B" & Rows.Count).End(xlUp).Row + 1
ActiveSheet.Rows(LRow).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("QChecklist4").Select
Cells(1, 1).Select
End If
Next
ActiveSheet.Protect "rdp"
End With
Sheets("QAnalysisForm").Activate
Sheets("QAnalysisForm").Protect "rdp"
Cells(1, 1).Select
'On Error Resume Next
'ActiveSheet.CheckBoxes.Delete
'Selection.FormatConditions.Delete
ScreenUpdating = True
For Each ws In Worksheets
ws.Protect "rdp"
ws.EnableSelection = xlUnlockedCells
Next
End Sub