对于这是一个非常基本的问题,我们深感抱歉,但多年来我一直在努力解决这个问题,无法解决。
为什么我的代码不断给出对象必需的错误?
Sub MatchUp()
For Each PastCell In Range("A1:A240")
For Each FutureCell In Range("P1:P240")
If FutureCell.Value = PastCell.Value Then
Range(FutureCell.Offset(0, 1), FutureCell.Offset(0, 9)).Cut _
Range(PastCell.Offset(0, 15), PastCell.Offset(0.23))
End If
Next
Next
Application.CutCopyMode = False
End Sub
答案 0 :(得分:0)
您有几个O型,另外最好避免复制/粘贴。见下文。有更干净的方法可以执行此操作,但是此(未经测试的)代码应使您到达终点……
Sub MatchUp()
Dim pastCell As Range, FuturCell As Range
For Each pastCell In Range("A1:A240").Cells
For Each FutureCell In Range("P1:P240").Cells
If FutureCell.Value = pastCell.Value Then
Range(pastCell.Offset(0, 15), pastCell.Offset(0, 23)).Value = Range(FutureCell.Offset(0, 1), FutureCell.Offset(0, 9)).Value
Range(FuturCell.Offset(0, 1), FuturCell.Offset(0, 9)).ClearContents
End If
Next FuturCell
Next pastCell
End Sub