# Copy & Paste VBA Challenge



## Carl Stephens (Dec 14, 2022)

Hello Team,
Can someone help me out with this code. It is supposed to paste the copied cells from one sheet and paste into the first blank row on the destination sheet, and it works the first time that you run the command, however, when the data changes and I run the macro again, it does not paste the newly copied information in the next blank row and puts the information at the end after last row that has any information on. Not too sure how to fix this one, hence my turning to the code gods. Thank you all.

Sub Schedule()
'
Dim wsData As Worksheet
Dim wsDest As Worksheet
Dim lr As Long

Application.ScreenUpdating = False

Set wsData = Worksheets("EPS")
Set wsDest = Worksheets("OT")

wsData.Unprotect ("EPS")
wsDest.Unprotect ("OT")

lr = wsData.Cells(Rows.Count, "AP").End(xlUp).Row

If wsData.FilterMode Then wsData.ShowAllData

With wsData.Rows(1)
.AutoFilter Field:=52, Criteria1:="Yes"
If wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
wsData.Range("BK2:BL" & lr).SpecialCells(xlCellTypeVisible).Copy
wsDest.Range("O" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
wsDest.Select
MsgBox wsData.Range("H1:H" & lr).SpecialCells(xlCellTypeVisible).Cells.Count - 1 & " new postings were copied to this tab." & vbCrLf & _
"Next, check in column C to see if there are any updates to any planned postings and send joining instructions if required.", vbInformation
Else
MsgBox "No new postings were found. Please check in column C to see if there are any updates to any planned postings and send joining instructions if required.", vbInformation
End If
.AutoFilter Field:=52
wsDest.EnableAutoFilter = True
wsData.EnableAutoFilter = True
wsData.Protect Password:="EPS", UserInterfaceOnly:=True
wsDest.Protect Password:="OT", UserInterfaceOnly:=True


End With

End Sub


----------



## dnorm (Yesterday at 7:56 AM)

Hi Carl

I am not brilliant at this but, looking at your code it is saying to locate and paste the data in the next blank cell in column O:-

wsDest.Range("O" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues

If you want it to start in a different column, then change the "O" to the correct column.


----------

