+ Reply to Thread
Results 1 to 2 of 2

Thread: Delete Row if Cells in specifc Column Equals "X" Macro Needed

  1. #1
    Registered User
    Join Date
    02-06-2012
    Location
    Charlotte, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    1

    Delete Row if Cells in specifc Column Equals "X" Macro Needed

    Hello All - I have an excel file with multiple tabs. Rows that need to be deleted have an "X" in column E. The "X" can appear in multiple locations. I would like to deleted those rows and keep the other rows in order across all tabs.

    I would like to have a macro to take care of this for me.

    Thank you in advance for the help !!!


    Ivan

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Delete Row if Cells in specifc Column Equals "X" Macro Needed

    Hello Ivanur55,

    This macro will clear the entire row that has an "X" in column E. I cleared the row rather than deleting it because you stated you wanted "keep the other rows in order across all tabs".
    Sub DeleteRows()
    
        Dim Data As Variant
        Dim LastRow As Long
        Dim R As Long
        Dim Wks As Worksheet
            
            For Each Wks In Worksheets
                LastRow = Wks.Cells(Rows.Count, "E").End(xlUp)
                Data = Wks.Range("E1:E" & LastRow).Value
                    For R = UBound(Data) To 1 Step -1
                        If Data(R, 1) = "X" Then Wks.Cells(R, "E").EntireRow.ClearContents
                    Next R
            Next Wks
            
    End Sub

    If you want to delete the row (this will shift all the rows below the deleted row up) then change the "If" statement in the macro to this...
                        If Data(R, 1) = "X" Then Wks.Cells(R, "E").EntireRow.Delete
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0