macros只能处理一个选定的单元格(如果select了两个或更多个单元格,则不起作用)

我有这个问题:我的代码只有在select了1个单元格的情况下才能正确执行,但是它不能用于多个单元格的select。 应该改变什么? 请帮忙。

当前代码:

Sub adddate() Dim cell As Range Dim r As Range Set r = Selection For Each cell In Selection If IsDate(r.Value) Then Selection.Cells = DateAdd("d", 28, CDate(r)) End If Next cell End Sub 

您正在设置select在r然后使用它。 cellvariables永远不会发挥作用。

 Sub adddate() Dim cell As Range Dim r As Range Set r = Selection For Each cell In Selection.Celss If IsDate(cell.Value2) Then 'r = selection, multiple cells can't be evaluated in IsDate, cell is just one single. cell Selection.Cells = DateAdd("d", 28, CDate(r)) End If Next cell End Sub