0
因此,我有一個宏可以剪切並複製「未完成的訂單」,並在數據(See previous post)下面插入這些行,然後在開放訂單數據上面粘貼標題。目前宏寫入的方式,如果沒有開放的訂單數據,它將標題一直寫到第65k行。如果在標題刪除標題下面沒有數據
見下面的代碼:
Dim LastRow, NewLast, MovedCount As Integer
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row 'Find last Row
NewLast = LastRow + 1 'NewLast tracks the new last row as rows are copied and pasted at the end
MovedCount = 0
For I = 2 To LastRow
If Left(Cells(I, 4), 1) = "O" Then 'Copy the row, increment NewLast and paste at the bottom.
Rows(I).Cut
'LastRow = LastRow - 1
Cells(NewLast + 3, 1).Select
ActiveSheet.Paste
Rows(I).Delete
I = I - 1 'Since we deleted the row, we must decrement i
MovedCount = MovedCount + 1 'Keeps track of number of rows moved so as not to overshoot the original last line
End If
If I + MovedCount = LastRow Then Exit For 'Exit For loop if we reached the original last line of the file
Next I
'inserts a header for the open section
Cells(1, 1).Select
Selection.End(xlDown).Select
nRowMax = Selection.Row
Selection.Offset(1, 0).Select
Selection.EntireRow.Copy
Selection.End(xlDown).Select
Selection.Offset(-1, 0).Select
Selection.PasteSpecial xlPasteFormats
ActiveCell.Select
ActiveCell = "Open Orders"
Application.CutCopyMode = False
所以我的問題是,我不是怎能停止,如果沒有開放的訂單數據或刪除頭,如果在它周圍有沒有數據被複制的標題。
我正在考慮放置一個IF,如果沒有頭THAN刪除標題下的數據。對不起,如果這是有點開放我覺得有一些方法可以去做這件事。