Extract year from a date and paste in next column
So I'm looking at a massive report at the moment and we get one in weekly and we want a macro to automate it. So one of the columns has numerous dates from 2012 to 2015 in it. I need to search for the 2014 dates and then from there put 2014 into the column directly on the right of it My code so far:
Sub Engagament_Hiring_Dates() Dim i As Long Dim k As Long For i = 2070 To 4000 If Year(BDi) = "2014" Then Cells(i, 57) = "2014" End If Next i End Sub
If your dates are in Column BD try this:
For i = 2070 To 4000 If Year(Cells(i, "BD")) = 2014 Then Cells(i, 57) = "2014" 'or simply 2014 End If Next i
Year Function returns an Integer, so you need to compare it to a number and not a string. This will work provided your values in Column BD are valid dates.
Also, you might want to check below on how to use Cells Property: