简体   繁体   English

如何在Excel 2013的列中的每个日期字段中添加一个月

[英]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.

相关问题 如何将2013年的每个日期都放在CSV / Excel表格中? - How do I put every date of 2013 in an CSV/Excel sheet? 如何在 excel 中自动创建和更新月份日期列表? - How do I automatically create and update month date list in excel? 如何在Excel中格式化日期列 - How do i Format a Date Column in Excel 我如何从月份和年份中获取第一个日期和最后一个日期| Excel |用于月份和年份的微调器| - How do i get first date and Last date from month and year |Excel |Used Spinner for Month and Year| 如何编写一个Excel公式来根据另一列中的日期来计算一列中值的数量? - How do I write an excel formula to count the number of a value in one column based off of a date in another column? 如何将此日期文本转换为Excel中的日期字段? - How do I convert this date text to a date field in excel? Excel:如何更改日期列以仅显示日期的月份? - Excel: How to change the date column to display only Month of the date? 如何从查询字段中删除导致Excel将字段解释为多个列或函数的字符 - How do I remove characters from a query field that cause Excel to interpret the field as more than one column or as a function 我该如何计算出一个列中每个值中需要多少才能在excel中累加一个总值? - How do I work out how many of each value in a column i would need to add up to a total value in excel? 使用Excel 2013,如何获得每5秒平均每10分钟的一列的平均值? - With Excel 2013, How can I get the average of one column that is every 5 seconds averaged into every 10 minutes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM