Since you specifically mention three slopes, I adjusted the code I gave you in the first place. If you want it to work for 1 or 2 slopes, just adjust the other code yourself (is good exercise for you
)
Sub test()
x = 2
a = Range("A1").Value
Do Until b <> ""
If Range("A" & x).Value <> a Then b = Range("A" & x).Value
x = x + 1
Loop
Do Until c <> ""
If Range("A" & x).Value <> a And Range("A" & x).Value <> b Then c = Range("A" & x).Value
x = x + 1
Loop
lastrow = Range("A65536").End(xlUp).Row
k = 0
l = 0
m = 0
For i = 1 To lr
If Cells(i, 1).Value <> a And Cells(i, 1).Value <> b And Cells(i, 1).Value <> c Then Cells(i, 1).EntireRow.Delete
If Cells(i, 1).Value = a Then
k = k + 1
If k > 1 then Cells(i, 1).EntireRow.Delete
End if
If Cells(i, 1).Value = b Then
l = l + 1
If l > 1 then Cells(i, 1).EntireRow.Delete
End if
If Cells(i, 1).Value = c Then
m = m + 1
If m > 1 then Cells(i, 1).EntireRow.Delete
End if
Next
End Sub
Again, if this helps you, please click the * below
Bookmarks