Results 1 to 3 of 3

Thread: VBA to move and delete cells based on contents

  1. #1

    VBA to move and delete cells based on contents



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi all,

    I need some VBA code that will:
    Find all the cells starting with "Area:Final" and delete them.
    Move the cell to the right of "Area:Final", always starting with "Zone:", to column A, same row.
    Move the cell next to this one, always starting with "Team:" to the row below "Zone", column A.

    For example:

    Before it was Area:Final... Zone:...... Team:.....

    I need

    Zone:....
    Team:....



    Thanks in advance to anyone who can help me out.

  2. #2
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,821
    Articles
    0
    Excel Version
    O365
    Code:
    Public Sub MoveData()Dim lastrow As Long
    Dim i As Long
    
    
        Application.ScreenUpdating = False
    
    
        With ActiveSheet
        
            lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
            For i = lastrow To 1 Step -1
            
                If .Cells(i, "A").Value Like "Area:Final*" Then
                
                    .Rows(i + 1).Insert
                    .Cells(i + 1, "A").Value = .Cells(i, "C").Value
                    .Cells(i, "A").Value = .Cells(i, "B").Value
                    .Cells(i, "C").Value = ""
                End If
            Next i
        End With
    
    
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Hi Bob,

    Thanks for this, however, when i paste it in to the visual basic, the top row goes red and when i run it there is a syntax error?
    Can you tell me what i am doing wrong?

Tags for this Thread

Posting Permissions

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