Delete Row in Column if data appears in Named Range

programsam

Board Regular
Joined
Feb 10, 2016
Messages
123
Greetings, I believe I've gotten as far as I can on this one.

I have a named range named "remAssoc" that updates dynamically using OFFSET - no problem there.

I have a sheet of data on a separate sheet "rAPRd" that has corresponding data in Column D, starting on Row 3. The code below "works" however, you have to run the macro multiple times because it does not delete all of the data on the first pass. Additionally, I would like to have it count the number of rows starting at D3 and shift rows up as well. How can this be modified?

Code:
Sub delAssoc()

Dim nRng As Range, rng As Range


Sheets("rAPRd").Activate


Set nRng = Range("remAssoc") 'Substitute actual name of range
'Set rng = Range("D3", ActiveSheet.Cells(Rows.Count, "D").End(xlUp)) 'get col d parameters
Set rng = Range("D:D", ActiveSheet.Cells(Rows.Count, "D").End(xlUp)) 'get col d parameters


    For Each c In rng 'Look at each item in col d
        If WorksheetFunction.CountIf(nRng, c.Value) = 1 Then 'Evaluate against named range
            c.EntireRow.Delete 'Delete rows with no match to named range
        End If
    Next c
    
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hope this helps.
Code:
Sub delAssoc()
Dim nRng As Range
Dim i As Long, LR As Long
    With Sheets("rAPRd")
        Set nRng = .Range("remAssoc") 'Substitute actual name of range
        LR = .cells(Rows.Count, 4).End(xlUp).row
        For i = LR To 3 Step -1
             If WorksheetFunction.CountIf(nRng, .cells(i, 4).Value) = 1 Then
                Rows(i).EntireRow.Delete
        Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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