erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 449
Just when I thought I could write a little code! Why does the following code paste to row 268 instead of the last row?
VBA Code:
Private Sub CommandButton1_Click()
' Get the worksheets
Dim shRead1 As Worksheet
Dim shRead2 As Worksheet
Dim shWrite As Worksheet
Dim Lastrow As Long
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Set shRead1 = ThisWorkbook.Worksheets("Personnel")
Set shRead2 = ThisWorkbook.Worksheets("This_year")
Set shWrite = ThisWorkbook.Worksheets("Hstry")
' This will copy the values only
shRead1.Range("P3:P66").Copy
shWrite.Range("A2" & Lastrow).PasteSpecial xlPasteValues
shRead2.Range("A2:G65").Copy
shWrite.Range("B2" & Lastrow).PasteSpecial xlPasteValues
MsgBox "done"
End Sub