是否可以简化以下代码?有什么办法可以缩短这个:
' Paste last value
Range(Cells(LastRowP + 1, 10), Cells(LastRowP + 1, 10)).Select
Selection.Cut
Range(Cells(LastRowP + 1, 9), Cells(LastRowP + 1, 9)).Select
ActiveSheet.Paste
Range(Cells(LastRowP + 2, 10), Cells(LastRowP + 2, 10)).Select
Selection.Cut
Range(Cells(LastRowP + 2, 9), Cells(LastRowP + 2, 9)).Select
ActiveSheet.Paste
Range(Cells(LastRowP + 3, 10), Cells(LastRowP + 3, 10)).Select
Selection.Cut
Range(Cells(LastRowP + 3, 9), Cells(LastRowP + 3, 9)).Select
ActiveSheet.Paste
这种情况一直持续到+20。我是 VBA 和编码的新手,所以请多多包涵:)
最佳答案
Range(Cells(LastRowP + 1, 10), Cells(LastRowP + 20, 10)).Cut _
Cells(LastRowP + 1, 9)
或者
Cells(LastRowP + 1, 10).Resize(20,1).Cut Cells(LastRowP + 1, 9)
关于vba - Excel VBA : Simplify long Code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19406801/