VBA Deleting rows - criteria x2

ListersPants

New Member
Joined
Nov 18, 2011
Messages
3
Hi,

I have inserted a table with a before and after scenario.

If a Model (Column B) has a 'Transmission Start' and a 'Transmission End' (Column A) then I want to delete the whole row for that model for the row which contains 'Transmission Start'. So that it leaves the row for that model which has 'Transmission End'. In the below example Models 356 and 873 are deleted as they have a 'Transmission Start' and 'End'.

I have cobbled the below together but it simply deletes any row which contains 'Transmission Start'.

Code:
With ActiveSheet
    .AutoFilterMode = False
    With Range("a1", Range("a" & Rows.Count).End(xlUp))
        .AutoFilter 1, "Transmission Start"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    .AutoFilterMode = False
End With

My data:
Before
Type
Model
Transmission start

<colgroup><col width="139"></colgroup><tbody>
</tbody>
356
Transmission start

<colgroup><col width="139"></colgroup><tbody>
</tbody>
873
Transmission end

<colgroup><col width="139"></colgroup><tbody>
</tbody>
356
Transmission start
896
Transmission end

<colgroup><col width="139"></colgroup><tbody>
</tbody>
873
Transmission start
231
Transmission end
111
After
Transmission end
356
Transmission start
896
Transmission end
873
Transmission start
231
Transmission end
111

<tbody>
</tbody>
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi ListersPants,

Give this a go, see if it works for you...

Code:
Sub RemoveDupeTrans()
LastRw = Range("A" & Rows.Count).End(xlUp).Row
  
For i = LastRw To 1 Step -1
    If UCase(Range("A" & i).Value) = "TRANSMISSION END" Then
        Srch = Range("B" & i).Value
        For j = LastRw To 1 Step -1
            If UCase(Range("A" & j).Value) = "TRANSMISSION START" And Range("B" & j).Value = Srch Then
                Rows(j).Delete
                Cntr = Cntr + 1
                GoTo Out
            End If
        Next
Out:
    End If
Next
MsgBox (Cntr & " Rows Deleted")
End Sub


Hope this helps,
Cheers,
Alan.
 
Upvote 0

Forum statistics

Threads
1,203,114
Messages
6,053,585
Members
444,674
Latest member
DWriter9

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