+ Reply to Thread
Results 1 to 7 of 7

How to delete all rows with the same name as a row that meet a certain criteria.

Hybrid View

  1. #1
    Registered User
    Join Date
    03-19-2010
    Location
    clayton
    MS-Off Ver
    Excel 2003
    Posts
    4

    How to delete all rows with the same name as a row that meet a certain criteria.

    Hi.
    I am becoming desperate, I have no idea how I can solve this problem.
    I need to delete all batches having incomplete tests on them with a macro.
    See example.
    Batch Test Status
    ZX320 a Complete
    ZX320 b InComplete
    ZX321 a Complete
    ZX321 b Complete
    ZX322 a InComplete
    ZX322 b Complete
    I hope someone can help.
    Br/ Martin

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: How to delete all rows with the same name as a row that meet a certain criteria.

    So you just want to loop through the rows and delete any where the Status = InComplete?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    03-19-2010
    Location
    clayton
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How to delete all rows with the same name as a row that meet a certain criteria.

    No i want to delete all rows on a batch if one of the tests is incomplete.
    / Martin

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: How to delete all rows with the same name as a row that meet a certain criteria.

    So in your example above, ZX320 and ZX322 would be deleted, but ZX321 would remain, correct? Would the Batch values always be in order?

  5. #5
    Registered User
    Join Date
    03-19-2010
    Location
    clayton
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How to delete all rows with the same name as a row that meet a certain criteria.

    Hi Dave.
    Correct. I can get at macro to arrange them by batch number if it helps. In the real spreadsheet there is more then two tests on each batch, and it is not the same number of tests on different batch
    Hope you can help.
    / Martin

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: How to delete all rows with the same name as a row that meet a certain criteria.

    Ok, assuming your results are in Column C, I believe this should do it:

    Public Sub shaihulud()
    
    Dim strRemove As String
    
    i = 2
    Do Until i = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(i, "C").Value = "InComplete" Then
            strRemove = Cells(i, "A").Value
            For j = 2 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
                If Cells(j, "A").Value = strRemove Then
                    Rows(j).Delete
                    j = j - 1
                End If
            Next j
            i = i - 1
        End If
        i = i + 1
    Loop
    
    End Sub

    Your Batch column does NOT have to be sorted, but it does have to be in column A.

  7. #7
    Registered User
    Join Date
    03-19-2010
    Location
    clayton
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How to delete all rows with the same name as a row that meet a certain criteria.

    Thx, ill try that. (if it works daves my new hero)
    /martin

+ 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.6.0 RC 1