我正在尝试为两个不同的列 (A) 和 (I) 运行此工作表更改事件...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, r As Range
Set A = Range("A:A")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each r In Inte
r.Offset(0, 1).Value = Date
Next r
Application.EnableEvents = True
End Sub
这个事件是我在这个论坛上找到的。它的目的是让每当数据输入到“a”列时,它会自动将日期输入到其右侧的单元格中。我希望这在工作表上发生两次。我不知道如何更改/添加它。我试图让它在我的电子表格上运行列 A 和 I 的逻辑。
最佳答案
只需扩展您设置为 A 变量的范围。
Set A = Range("A:A, I:I")
改写为,
Private Sub Worksheet_Change(ByVal Target As Range)
if not intersect(range("A:A, I:I"), target) is nothing then
'add error control
on error goto safe_exit
'don't do anything until you know something has to be done
dim r as range
Application.EnableEvents = False
For Each r In intersect(range("A:A, I:I"), target)
r.Offset(0, 1).Value = Date 'do you want Date or Now?
Next r
end if
safe_exit:
Application.EnableEvents = True
End Sub
关于vba - 尝试两次运行工作表更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48898113/