PDA

View Full Version : Delete cell range not whole row



suny100
05-26-2011, 02:00 PM
i want to delete range that i copy and paste it in other sheet but i want to delete the range not the rows, when i write the delete sentence it run the whole code for the half of data and other not , i don't know where is the mistak in my code.

Dim iRow As Long
For iRow = 1 To 10000
If Cells(iRow, "E").Value = "1" Then
Range(Cells(iRow, 2), Cells(iRow, 4)).Copy
NextRow = iRow + 3
Sheet9.Cells(NextRow, 2).PasteSpecial xlPasteValues
Range(Cells(iRow, 2), Cells(iRow, 5)).Delete Shift:=xlUp
End If

Next iRow

CharlesH
05-26-2011, 02:13 PM
Hi, This was ask here. http://www.excelforum.com/excel-programming/777491-delete-range-not-rows.html Please do not double post unless you refer to the post in another forum.

p45cal
05-26-2011, 05:41 PM
Since you're likely to want to retain the order things appear in on Sheet9. then don't delete anything in the loop, just copy stuff, then do a second loop to delete stuff, but go up the list, not down it with:
For irow = 10000 to 1 step -1