erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 449
If I make this simple code work I can modify to fit my needs. I archive data once a year. So col.A contains the current year. Just want check to see if the current year has been copied over to "shWrite". If it has msgbox says "already done". If not, go a head and paste. Then 2023 come around and it looks for the last line of 2022 entries and goes through the same sequence.
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
'*******
Dim lr As Range
'*******
Set shRead1 = ThisWorkbook.Worksheets("Personnel")
Set shRead2 = ThisWorkbook.Worksheets("This_year")
Set shWrite = ThisWorkbook.Worksheets("Hstry")
Set Lastrow = shWrite.Range("A:A").End(xlUp).EntireRow
If Lastrow = Year(Now()) Then
MsgBox "aready exist"
Else
MsgBox "go ahead and Paste"
' This will copy the values only
shRead1.Range("P3:P66").Copy 'Reads current year
shWrite.Range("A" & Lastrow + 1).PasteSpecial xlPasteValues
shRead2.Range("A3:H65").Copy
shWrite.Range("B" & Lastrow + 1).PasteSpecial xlPasteValues
MsgBox "Transfer Successful"
End If
End Sub