Sub EX1()
Sheets("訂單明細 -4月").Activate
With Sheets("訂單明細 -3月")
For C = 7 To 31
Cells(500, C).End(xlUp).Offset(3) = .Cells(500, C).End(xlUp).Offset(-2)
Cells(500, C).End(xlUp).Offset(1) = .Cells(500, C).End(xlUp).Offset(-1)
Cells(500, C).End(xlUp).Offset(1) = .Cells(500, C).End(xlUp)
Next
End With
End Sub
這樣寫程式別人大概也很難懂,因為不會有人邊用End邊填值.......
如果把上面3行程式對調結果會大不同,提供一個比較"正常"的寫法如下
Sub EX2()
'找尋F攔 "庫存=已排生產-客戶訂單" 這列
R3 = ['訂單明細 -3月'!F500].End(xlUp).Row
R4 = ['訂單明細 -4月'!F500].End(xlUp).Row
Sheets("訂單明細 -4月").Activate
With Sheets("訂單明細 -3月")
For C = 7 To 31
Cells(R4 + 3, C) = .Cells(R3 + 3, C)
Cells(R4 + 4, C) = .Cells(R3 + 4, C)
Cells(R4 + 5, C) = .Cells(R3 + 5, C)
Next
End With
End Sub作者: JT1221 時間: 2020-4-1 10:21