Delete rows with reference

Sathisc

Board Regular
Joined
Jul 29, 2008
Messages
103
Hi,

I have a data consists of 3 column as given below

ABC
10252554SEAC
10252554LSFMC
10252554DGPMC
10252554BOOMC
10252554TSDBTO
10252554THDBTO
10252548SEAP
10252548LSFMC
10252548DGPMC
10252548BOOMC
10252548TSDBTO
10252548THDBTO

<tbody>
</tbody><colgroup><col span="3"></colgroup>


scenario - If Column B consists of "SEA" and Colum C with "C" the rows(entire) which has the number 10252554 needs to get deleted.

Help is much appreciated

Output required

ABC
10252548SEAP
10252548LSFMC
10252548DGPMC
10252548BOOMC
10252548TSDBTO
10252548THDBTO

<tbody>
</tbody><colgroup><col span="3"></colgroup>
 
One question that will help me formulate a plan...
Is there any possibility for duplicates with the "SEA/C" combination?
Meaning, could you have two (or more) rows that have "SEA/C/10252554"?
If there is no possibility of duplicates, it will make it much easier.
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
One question that will help me formulate a plan...
Is there any possibility for duplicates with the "SEA/C" combination?
Meaning, could you have two (or more) rows that have "SEA/C/10252554"?
If there is no possibility of duplicates, it will make it much easier.

the combination will appear only once and there is no duplication
 
Upvote 0
Try this:
Code:
Sub MyDeleteRows()

    Dim rng As Range, rngVisible As Range
    Dim rCell As Range, myArray() As Variant, i As Long
    Dim RowCt As Long
    
    Application.ScreenUpdating = False
    
'   Get range of data
    Set rng = Range("A1:C" & Cells(Rows.Count, "A").End(xlUp).Row)
    
'   See how many rows have "SEA" in column B and "C" in column C
    RowCt = Application.WorksheetFunction.CountIfs(Range("B:B"), "SEA", Range("C:C"), "C")
    
'   If RowCt>0 then delete rows with column A = 10252554
    If RowCt > 0 Then
'       Filter out records with "SEA" in column B and "C" in column C
        rng.AutoFilter Field:=2, Criteria1:="SEA"
        rng.AutoFilter Field:=3, Criteria1:="C"
'       Loop though visible rows storing codes from column A in array
        With rng
            Set rngVisible = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                  .SpecialCells(xlCellTypeVisible)
        End With
        For Each rCell In rngVisible
            i = i + 1
            ReDim Preserve myArray(1 To i)
            myArray(i) = rCell
        Next rCell
'       Loop through array to build criteria
        For i = LBound(myArray) To UBound(myArray)
'           Filter data
            ActiveSheet.AutoFilter.ShowAllData
            rng.AutoFilter Field:=1, Criteria1:=myArray(i)
'           Delete visible data after filter
            Application.DisplayAlerts = False
            ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
            Application.DisplayAlerts = True
'           Remove filters
            ActiveSheet.AutoFilter.ShowAllData
            Next i
    End If
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Here is another option to try in a copy of your workbook.
Code:
Sub RemoveRows()
  Application.ScreenUpdating = False
  With Range("A1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    Range("J2").Formula = Replace("=COUNTIFS(A$2:A$#,A2,B$2:B$#,""SEA"",C$2:C$#,""C"")", "#", .Rows.Count)
    .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("J1:J2"), Unique:=False
    .Offset(1).EntireRow.Delete
    If .Parent.FilterMode Then .Parent.ShowAllData
    Range("J2").ClearContents
  End With
  Application.ScreenUpdating = True
End Sub


If you happen to have a very large amount of data and both the suggested methods are too slow, post back with details as there would be a faster way (but longer code to write)
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,565
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top