Hello folks:
I have a rather large spreadsheet that I want to reduce in size. Basically, I have a named range called nameList, I want to delete every row in sheet 1 where values in column A do not match those in the named range.
So I worked out this code, but I keep getting an error: Run time error 1004. Appplication defined or object defined error.
I have a rather large spreadsheet that I want to reduce in size. Basically, I have a named range called nameList, I want to delete every row in sheet 1 where values in column A do not match those in the named range.
So I worked out this code, but I keep getting an error: Run time error 1004. Appplication defined or object defined error.
Code:
Private Sub Test()
Dim namedRng As Range
Dim rng As Range
Dim c As Variant
Set namedRng = Range("nameList")
Set rng = Range("A2:A", Sheet1.Cells(Rows.Count, "A").End(xlUp))
For Each c In rng
If WorksheetFunction.CountIf(nRng, c.Value) = 0 Then
c.EntireRow.Delete
End If
Next
End Sub