英文:
Worksheet_Change multiple changes
问题
以下是翻译好的部分:
我有以下问题。如果我删除多个单元格或对多个单元格执行选择编辑操作,我会收到错误消息。我的代码如下;
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value <> PreviousValue Then
Sheets("log").Cells(80000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " has changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value &
End If
End Sub
我做错了什么?
英文:
I have the following question. I get an error if I delete multiple cells or perform a selection edit on multiple cells. My code is as follows;
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value <> PreviousValue Then
Sheets("log").Cells(80000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " heeft cel " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value &
End If
End Sub
What am I doing wrong?
答案1
得分: 2
如果Target
是一个多单元格范围,那么比较Target.Value <> PreviousValue
将失败(Target.Value
然后是一个二维数组)。
使用循环来比较每个单独的单元格:
Dim rng as Range
For Each rng in Target
If rng.Value <> PreviousValue Then
英文:
If Target
is a multi-cell range, then the comparison Target.Value <> PreviousValue
will fail (Target.Value
is then a 2D array).
Use a loop to compare each individual cell:
Dim rng as Range
For Each rng in Target
If rng.Value <> PreviousValue Then
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论