Hi there so I have this problem whereby I am not able to copy a row of data from sheet(general_logsheet) to the new sheet. I only want to paste the data that has the current year in it onto a new sheet. The catch is that every year the new sheet will be created named as (year(date) & "_logged"). Example: 2020_Logged, 2021_Logged.
VBA Code:
Private Sub LoggedAss_Click()
Dim lastrow As Long, erow As Long, i As Long
Dim mydate As Date
Dim currentDate As Date
lastrow = Sheets("General_LogSheet").Cells(Rows.Count, 1).End(xlUp).Row
currentDate = Year(Date)
With Sheets("General_LogSheet")
.Select
.Range("A1").Select
End With
For i = 2 To lastrow
mydate = Cells(i, 4)
If mydate = currentDate Then
erow = Sheets(Year(Date) & "_logged").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Range(Cells(i, 1), Cells(i, 4)).COpy Destination:=Sheets(Year(Date) & "_logged").Cells(erow, 1)
End If
Next i
End Sub