hi.
i need to copy data from one worksheet to another based on certain criteria.
i wrote the following simple initial code to do the job. i now have one problem and one question:
1 - the code works fine when i run it once. if i run it the second time, without any changes to worksheets, i expect it to simply put the same data on top of what it copied already. but instead it does something bizarre - it pushes down the data it copied on the first run, ignores the 'if' statement, and copies just a few top rows of the source sheet where the previously copied data was.
2 - generally, is this code good for the task? any glaring deficiencies? i know there are a few ways to copy-paste data between sheets (and workbooks), but not being a true programmer, i really have no clue about the nuances - efficiency, 'error-proneness', etc.
thanks,
len
i need to copy data from one worksheet to another based on certain criteria.
i wrote the following simple initial code to do the job. i now have one problem and one question:
1 - the code works fine when i run it once. if i run it the second time, without any changes to worksheets, i expect it to simply put the same data on top of what it copied already. but instead it does something bizarre - it pushes down the data it copied on the first run, ignores the 'if' statement, and copies just a few top rows of the source sheet where the previously copied data was.
2 - generally, is this code good for the task? any glaring deficiencies? i know there are a few ways to copy-paste data between sheets (and workbooks), but not being a true programmer, i really have no clue about the nuances - efficiency, 'error-proneness', etc.
thanks,
len
Code:
Sub FileCompleted()
copyrow = 3
pasterow = 3
totrows = WorksheetFunction.CountA(Sheets("ALLORDERS").Range("a:a")) - 2
For r = copyrow To totrows
If Range("V" & r) = "Completed" Then
Sheets("COMPLETEDv2").Range("A" & pasterow & ":Z" & pasterow).Value = _
Sheets("ALLORDERS").Range("A" & r & ":Z" & r).Value
pasterow = pasterow + 1
End If
Next r
End Sub