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

Answers


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:

Using Cells


Need Your Help

Eclipse buildpath automatically taking all JARs of a linked directory

eclipse dynamic linked-list buildpath

This issue is a variation on the one described here: Eclipse buildpath automatically taking all JARs of a internal directory

“Variable $foo will not stay shared” Warning/Error in Perl While Calling Subroutine

linux perl unix

Update3: If you like this posting please don't upvote me but upvote the genius answer by DVK below.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.