
求一個巨集可以執行下列動作:
當A1.A2.B2.A3.B3有資料存在時,想要將B2移至B1,B3移至I1,並且刪除A2和A3的內容。
並且當此巨集需要在下一個儲存格執行時不會干涉到上方資料,意即:
當A2.A3.B3.A4.B4有資料存在時,想要將B3移至B2,B4移至I2,並且刪除A3和A4的內容。
有解嗎???
Sub test()
Dim i As Integer, e As Integer
e = InputBox(Prompt:="請輸入資料最後列數")
For i = 1 To e
If Cells(i, 1) <> "" Or Cells(i + 1, 1) <> "" Or Cells(i + 2, 1) <> "" Or Cells(i + 1, 2) <> "" Or Cells(i + 2, 2) <> "" Then
Cells(i + 1, 2).Select
Selection.Cut
Cells(i, 2).Select
ActiveSheet.Paste
Cells(i + 2, 2).Select
Selection.Cut
Cells(i, 9).Select
ActiveSheet.Paste
Cells(i + 1, 1) = ""
Cells(i + 2, 1) = ""
End If
Next i
End Sub