0
我正在创建一个小程序,它将在表格“当前”的列I中查找更改。如果找到更改,它将会剪切,并将整列粘贴到“完成”工作表的最后一行。看起来,当它切割时,它会陷入无限循环,导致它永远不会弹出“Made it”消息框。我怎样才能重新证明地址的正确性,以避免这个问题呢?无限循环与目标地址
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Dim LastRowCompleted As Long
LastRowCompleted = Sheets("completed").Cells(Sheets("completed").Rows.Count, "A").End(xlUp).Row
LastRowCompleted = LastRowCompleted + 1 'Next row after last row
Set KeyCells = Range("I:I")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
MsgBox "Cell " & Target.Address & " has changed."
MsgBox Range(Target.Address).Row
MsgBox Range(Target.Address).Column
'Cut and Paste Row
Range(Range(Target.Address).Row & ":" & Range(Target.Address).Row).Cut Sheets("completed").Range(LastRowCompleted & ":" & LastRowCompleted)
MsgBox "Made it."
End If
End Sub
旁注:'(范围(Target.Address).Row& “:” &范围(Target.Address).Row ).Cut'可以简单地写成'Target.EntireRow.Cut' –