PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
MsOf13 Delete entire row based on Cell value-VBForums
Results 1 to 7 of 7

Thread: Delete entire row based on Cell value

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2017
    Posts
    103

    Delete entire row based on Cell value

    Hello everyone,
    I have lot of data in my work book. In that i need to delete the row which contains Letter "E" in column E and the other cells are blank.

    So if the rows having letter "E" on column E and the next cells are blank , should entire row will be deleted.

    I have code to remove if the cells are blank from "F"....but it should remove if Column E has value "E" rest cells are blank....then only it should remove entire row.

    Code:
    Sub Test()
    On Error Resume Next
    Columns("F").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub

    Thanks in Advance

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,500

    Re: Delete entire row based on Cell value

    What with cells left of Column E? Or only delete entire row if right of column E is blank?
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2017
    Posts
    103

    Re: Delete entire row based on Cell value

    Hi Zvoni,
    Thanks for your reply.
    Actually I have some data on cells left of column E.. I don't need that...I just want to delete entire row if right of column E is blank.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,824

    Re: Delete entire row based on Cell value

    you can try like
    Code:
    For rw = Cells(Rows.Count, 5).End(xlUp).Row To 1 Step -1
        If Cells(rw, 5) = "E" Then
            If Application.CountBlank(Cells(rw, 6).Resize(, Columns.Count - 6)) = Cells(rw, 6).Resize(, Columns.Count - 6).Cells.Count Then Cells(rw, 5).EntireRow.Delete
        End If
    Next
    for a large amount of data it may be better to use union to append all the rows to b deleted to a range object and then just do a single delete for that range
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,500

    Re: Delete entire row based on Cell value

    Another Approach might be something along the lines

    Aircode:
    vb Code:
    1. Dim sTemp As String
    2. If MyWorksheet.Cells(CurRow, 5)="E" Then
    3.    sTemp=vbNullstring
    4.    For i=6 To LastColumn   'Determine LastColumn beforehand with the function of your choise
    5.              sTemp=sTemp & Trim(MyWorksheet.Cells(CurRow, i))   'Using Trim to catch Blanks
    6.        Next
    7.        If MyWorksheet.Cells(CurRow, 5) & sTemp="E" Then MyWorksheet.Rows(CurRow).Delete
    8. End If
    Last edited by Zvoni; Sep 17th, 2018 at 05:09 AM. Reason: Had a mistake
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2017
    Posts
    103

    Re: Delete entire row based on Cell value

    Hello Westconn and Zvoni
    Thanks for your code.
    It's working as i want. and Zvoni i have tested your code but i got Error on this line.
    Code:
      If MyWorksheet.Cells(CurRow, 5)="E" Then

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,500

    Re: Delete entire row based on Cell value

    Well, what's the value of CurRow?
    CurRow is just a placeholder.
    You have to build a loop outside of it iterating through your rows.
    Westconn showed you how (looping backwards)
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width