将一天添加到一行中所有单元格的日期字段 - VBA

Add one day to a date field in all cells in a row - VBA

我在 D1 单元格中有一个日期 (2/1/2018),现在我想使用 VBA

在从 D2 到 AH 的所有单元格中将日期增加一个

有什么建议吗?

谢谢 斯里

请注意,如果变量数据类型设置为Date,则与1相加时日期会增加。

VBA:

Sub DateIncreaser

    Dim d as Date
    d = Selection.value 'Assign appropriated value to d variable.
    d = d + 1
    debug.print d 'This optional line shows the result in immediate window.
    Range("D2").Value = d

End Sub

更新1

Sub DateIncreaser()

    Dim d As Date
    Dim i As Integer
    Dim InitialColumnIndex As Integer
    Dim FinalColumnIndex As Integer
    Dim RowsIndex As Long

    InitialColumnIndex = 1
    FinalColumnIndex = 34 'Representative AH Column
    RowsIndex = 2
    d = Selection.Value 'Source date value

    For i = InitialColumnIndex To FinalColumnIndex
        d = d + 1
        Cells(RowsIndex, i).Value = d
    Next i

End Sub

更新2

Sub DateIncreaser()

    Dim d As Date
    Dim i, j As Integer
    Dim InitialColumnIndex As Integer
    Dim FinalColumnIndex As Integer
    Dim RowsIndex As Long

    InitialColumnIndex = 1
    FinalColumnIndex = 34 'Representative AH Column
    RowsIndex = 2

    For j = 1 To Sheets.Count

        d = Range("D1").Value 'Source date value

        For i = InitialColumnIndex To FinalColumnIndex
            d = d + 1
            Worksheets(j).Cells(RowsIndex, i).Value = d
        Next i

    Next j

End Sub