我设置了一个宏,可以清除电子表格上的内容。在此宏的末尾,我想选择其中已包含日期的特定单元格,然后将当前日期替换为当前日期 +1。在网上搜索后,我找到了 DateAdd 函数,但我对 VBA 还很陌生,并且很难正确编写该函数。选择必要的单元格后,我如何将日期更改为第二天?
最佳答案
从字面上理解你的问题,你可以这样做:
' Here goes the code where you select the date cells you want to increment
' ...
' Now increment them by 1 day:
Dim cell As Range
For Each cell In Selection
cell.Value = cell.Value + 1 ' adds 1 day
Next cell
Date 数据类型的单位是天。所以加 1 就等于一天。
关于excel - 使用 VBA 在单元格中添加迄今为止的一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8156271/