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删除标题下的数据。对不起,如果这是有点开放我觉得有一些方法可以去做这件事。