D
DJ
Hello - I'm looking for help on cutting and pasting rows between two
worksheets while enumerating a collection.
Sheet1 (wsADJUSTED) contains rows of invoice information. For each invoice
having a status of 9 in column P, I'd like to cut and paste the entire row
from Sheet1 to Sheet2 (wsDELETED), and delete the original row from Sheet1.
Here's a code snippet:
For Each AdjustedInvoicesCell In AdjustedInvoices
If (StrComp(AdjustedInvoicesCell.Offset(0, 11), "9")) = 0 Then
Worksheets(wsADJUSTED).Rows(n).Cut
Destination:=Worksheets(wsDELETED).Range("A65536").End(xlUp).Offset(1, 0)
Worksheets(wsADJUSTED).Rows(n).Delete
End If
Next AdjustedInvoicesCell
There are two problems with this that I can't figure out:
1. All rows in Sheet1 (wsADJUSTED) don't get processed. Is this because I'm
deleting rows from a collection while trying to enumerate it at the same
time? How can this be avoided?
2. The rows pasted to Sheet2 (wsDELETED) overwrite one another. I can't find
a solution to advance the row on Sheet2 where the cut row from Sheet1 should
be pasted.
All suggestions are appreciated. Thank you.
worksheets while enumerating a collection.
Sheet1 (wsADJUSTED) contains rows of invoice information. For each invoice
having a status of 9 in column P, I'd like to cut and paste the entire row
from Sheet1 to Sheet2 (wsDELETED), and delete the original row from Sheet1.
Here's a code snippet:
For Each AdjustedInvoicesCell In AdjustedInvoices
If (StrComp(AdjustedInvoicesCell.Offset(0, 11), "9")) = 0 Then
Worksheets(wsADJUSTED).Rows(n).Cut
Destination:=Worksheets(wsDELETED).Range("A65536").End(xlUp).Offset(1, 0)
Worksheets(wsADJUSTED).Rows(n).Delete
End If
Next AdjustedInvoicesCell
There are two problems with this that I can't figure out:
1. All rows in Sheet1 (wsADJUSTED) don't get processed. Is this because I'm
deleting rows from a collection while trying to enumerate it at the same
time? How can this be avoided?
2. The rows pasted to Sheet2 (wsDELETED) overwrite one another. I can't find
a solution to advance the row on Sheet2 where the cut row from Sheet1 should
be pasted.
All suggestions are appreciated. Thank you.