如果有人更改某些文本,我正在使用以下代码来更新日期。问题是如果我想插入更多行,因为我已将范围定义为"D9:D16"。
有没有办法使此代码能够观察插入的新行?
Private Sub Worksheet_Change(ByVal Target As Range)
'Hvis du på noget tidspunkt tilføjer flere rows, så sig til.
Application.EnableEvents = False
If Not Intersect(Range("D9:D16"), Target) Is Nothing Then
Target.Offset(, -2).Formula = "=UDF_Now()"
Select Case MsgBox("Er ""Updated by"" den rigtige?", vbYesNo)
Case Is = vbNo
Target.Offset(, -1).Activate
End Select
End If
Application.EnableEvents = True
End Sub
Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
可用于查找上次使用的行,因此一旦您插入新行,结果就会递增 1。
所以尝试这样的东西:
If Not Intersect(Range("D9:D" & Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row), Target) Is Nothing Then