programsam
Board Regular
- Joined
- Feb 10, 2016
- Messages
- 85
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?
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