宏仅适用于一个选定的单元格(如果选择了2个或更多单元格,则不起作用)

时间:2016-08-10 09:06:51

标签: excel vba

我遇到了这个问题:我的代码只有在选择了1个单元格时才能正确执行,它不适用于多个单元格选择。应该改变什么?请帮忙。

当前代码:

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

1 个答案:

答案 0 :(得分:0)

您正在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 中设置选择,然后使用它。 var data = {"questions": ["Q1", "Q2", "Q3"],"details": [{"name": "Alex","values": [27, 2, 14]}, {"name": "Bill","values": [40, 94, 18]}, {"name": "Gary","values": [64, 32, 45]}]}, question = "Q1", qIndex = data.questions.indexOf(question); for (var i = 0, len = data.details.length; i < len; i++) { data.details[i].single = data.details[i].values[qIndex]; } console.log(data.details);变量永远不会发挥作用。

| formail -I ''