PDA

View Full Version : Solved: Problem delete and replace item



Nader
03-19-2008, 10:29 AM
I tired this code to delete some groups of items and replace the their below item in their place as you see in the pic.

Dim LastRow As Long, i As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1
If UCase(Range("B" & i).Value) = "C" And Range("A" & i).Value = 33 Then
Range("A" & i).Delete xlShiftUp
Range("B" & i).Resize(, 5).Delete xlShiftUp

End If
Next i


The problem that I faced, the result didn't keep the last arrangement, it's mean it left tow rows not one row as in the first. How to fix this problem. By the way I don't want to delete and replace a row only the items
I hope I'm clear

mdmackillop
03-19-2008, 04:28 PM
Dim LastRow As Long, i As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = LastRow To 1 Step -1
If UCase(Range("B" & i).Value) = "C" And Range("A" & i).Value = 33 Then
If Application.CountA(Range("A" & i - 1).Resize(, 6)) = 0 Then
Range("A" & i - 1).Resize(, 6).Delete xlShiftUp
Range("A" & i - 1).Resize(, 6).Delete xlShiftUp
Else
Range("A" & i).Resize(, 6).Delete xlShiftUp
End If
End If
Next i

Nader
03-19-2008, 05:30 PM
Thank you very mush for your effort.