从日期中提取年份并粘贴到下一列

Extract year from a date and paste in next column

所以我现在正在查看大量报告,我们每周都会收到一份报告,我们需要一个宏来自动化它。 因此,其中一列包含从 2012 年到 2015 年的许多日期。 我需要搜索 2014 年的日期,然后从那里直接将 2014 年放入它右侧的列中 到目前为止我的代码:

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

如果您的日期在 BD 列中,试试这个:

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 和 Integer,因此您需要将其与数字而不是字符串进行比较。
如果您在 BD 列中的值是有效日期,这将起作用。

此外,您可能想查看下面的内容,了解如何使用 Cells Property:

Using Cells