Copy & Paste VBA Challenge

Carl Stephens

New Member
Joined
Jan 3, 2017
Messages
22
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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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.
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top