Thank you, but I don't want to extract the results elsewhere. What is required is to use the VBA code to delete the rows that contain duplicate values, while keeping the smallest and largest value for each duplicate name on column b.Have you tried:
Cell I1
Make sure you encompass the entire rangeExcel Formula:=UNIQUE(B1:B21)
Then in Cell L2
Fill downExcel Formula:=MAXIFS(E:E,B:B,I2)
That worked when I tested it.
Sub sofas()
Dim I As Integer
Dim A As Integer
Dim nme As String
For I = 21 To 2 Step -1
nme = Range("B" & I).Value
A = Application.WorksheetFunction.MaxIfs(Range("E:E"), Range("B:B"), nme)
If Range("E" & I).Value < A Then
Range("B" & I & ":E" & I).Delete
Else
End If
Next I
End Sub
Thank you. The code has been modified to suit my request. I appreciate your effortStart at the bottom and work your way to the top and check to see if the value in E equals the maxifs of Range B. If not, delete, else continue.
This is some very simplistic code that will work. You can adjust it to become more versatile to suit your needs.
VBA Code:Sub sofas() Dim I As Integer Dim A As Integer Dim nme As String For I = 21 To 2 Step -1 nme = Range("B" & I).Value A = Application.WorksheetFunction.MaxIfs(Range("E:E"), Range("B:B"), nme) If Range("E" & I).Value < A Then Range("B" & I & ":E" & I).Delete Else End If Next I End Sub