我在D1单元格中有一个日期(2/1/2018),现在我想使用VBA将所有单元格中的日期从D2增加到AH
有什么建议吗?
感谢 SREE
答案 0 :(得分:0)
请注意,如果可变数据类型设置为Date
,则在与1求和时将增加日期。
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
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
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