[英]How do I add one month to each date field in a column in Excel 2013
I have a column of date fields that contain different dates. 我有一列包含不同日期的日期字段。 I want to add 1 month to each of the dates. 我想为每个日期添加1个月。
So if my column/row is the following 所以如果我的列/行如下
A3: 1/2/2014
A4: 1/4/2014
A5: 1/10/2014
A6: 1/15/2014
Whatever formula or method I run will change everything to 无论我运行哪种公式或方法,都将更改为
A3: 2/2/2014
A4: 2/4/2014
A5: 2/10/2014
A6: 2/15/2014
You can use the EDATE function which adds a number of months to a give date. 您可以使用EDATE函数,将给定日期增加数月。
EDATE(A1, 1)
will add one month to the date in cell A1. 将为单元格A1中的日期添加一个月。
That won't do what I need it to do though. 那不会做我需要做的。 I want to update the existing cells to increase the date in each of them. 我想更新现有单元以增加每个单元中的日期。 I updated my question to (hopefully) make it clearer. 我将问题更新为(希望)更加清楚。 – Scott 33 mins ago –斯科特33分钟前
From the comment under the deleted answer(Jerry) ( Since I can still see them :p ), I guess you want to use VBA. 从已删除的答案(Jerry)下的注释中( 由于我仍然可以看到它们:p ),我想您想使用VBA。 If that is the case then see this.You need to use the DateAdd()
如果是这种情况,请参见此。您需要使用DateAdd()
If you check the Excel's help, DateAdd
returns a Variant (Date) containing a date to which a specified time interval has been added. 如果您检查Excel的帮助, DateAdd
将返回一个变量(日期),其中包含已添加指定时间间隔的日期。
Syntax 句法
DateAdd(interval, number, date) DateAdd(间隔,数字,日期)
The interval argument has these settings: interval参数具有以下设置:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Paste this in a module. 将此粘贴到模块中。
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long, i As Long
'~~> Change this to the relevant sheet
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 3 To lRow
.Range("A" & i).Value = DateAdd("m", 1, .Range("A" & i).Value)
Next i
End With
End Sub
Since in your example all your dates are in January, this should work: enter 31
in some cell and copy. 由于在您的示例中,所有日期都是在一月,所以这应该起作用:在某些单元格中输入31
并复制。 Select your dates and Paste Special… Add. 选择您的日期,然后选择特殊粘贴…添加。 Simple, but big disadvantage is that this only works for 7 months of the year! 简单但很大的缺点是,此功能仅在一年的7个月内有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.