Consulting

Results 1 to 3 of 3

Thread: Solved: Problem delete and replace item

  1. #1

    Question Solved: Problem delete and replace item

    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.

    [vba]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
    [/vba]

    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
    Last edited by Nader; 03-19-2008 at 04:06 PM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]
    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

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thank you very mush for your effort.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •