如果在 A:AE 范围内进行任何更改,则更新列 "X",但保留同一行
Update column "X" if any changes made within A:AE range, but keep the same row
我正在尝试创建一个代码,如果 A:AE 中的任何单元格发生任何变化,该代码将更新列 "X" 中的日期值。更新功能必须只适用于同一行。例如,我更改了 A1 并更新了 X1。非常感谢!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R1 As Range
Dim R2 As Range
Dim InRange As Boolean
Set R1 = Range(Target.Address)
Set R2 = Range("A:AE")
Set InterSectRange = Application.Intersect(R1, R2)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
If InRange = True Then
R1.**Offset(0, 1)**.Value = Now()
End If
Set R1 = Nothing
Set R2 = Nothing
End Sub
您可以使用 Target.Row 来确定行,因此您可以只使用:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 31 And Target.Column <> 24 Then
Cells(Target.Row, 24) = Now()
End If
End Sub
我正在尝试创建一个代码,如果 A:AE 中的任何单元格发生任何变化,该代码将更新列 "X" 中的日期值。更新功能必须只适用于同一行。例如,我更改了 A1 并更新了 X1。非常感谢!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R1 As Range
Dim R2 As Range
Dim InRange As Boolean
Set R1 = Range(Target.Address)
Set R2 = Range("A:AE")
Set InterSectRange = Application.Intersect(R1, R2)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
If InRange = True Then
R1.**Offset(0, 1)**.Value = Now()
End If
Set R1 = Nothing
Set R2 = Nothing
End Sub
您可以使用 Target.Row 来确定行,因此您可以只使用:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 31 And Target.Column <> 24 Then
Cells(Target.Row, 24) = Now()
End If
End Sub