Hello can the following code be altered so that wherever Sheet 3 is mentioned it refers to the active sheet instead?
Thank you very much
Sub CopyPasteRows1()
Dim lr As Long, r As Long, nr As Long
Const wsPassword As String = "password"
On Error GoTo exitsub
Sheet2.Unprotect Password:=wsPassword
With Application
.ScreenUpdating = False: .EnableEvents = False
End With
'Find last row with data in column on Sheet3
lr = Sheet3.Cells(Sheet3.Rows.Count, "O").End(xlUp).Row
'Loop through all rows starting on row 2 on Sheet3
For r = 2 To lr
If Sheet3.Cells(r, "O") = "X" Then
'Copy data to from columns C-K to Sheet2
Sheet3.Range("C" & r).Resize(, 9).Copy
'Find next available row on Sheet2
nr = Sheet2.Cells(Sheet2.Rows.Count, "C").End(xlUp).Row + 1
'Paste values from columns C-K to Sheet2
Sheet2.Cells(nr, "C").PasteSpecial xlPasteValues
End If
Application.CutCopyMode = False
Next r
Sheet2.Protect Password:=wsPassword
Sheet3.Range("K7:K100").ClearContents
Sheet3.Range("H7:I100").ClearContents
Sheet3.Range("O7:O100").ClearContents
exitsub:
With Application
.ScreenUpdating = True: .EnableEvents = True
End With
If Err = 0 Then
MsgBox "Service entries have been posted to 'Service Log'!", 64, "Entry Complete"
Else
MsgBox (Error(Err)), 48, "Error"
End If
Range("G1").Select
End Sub
Bookmarks