ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   select and delete certain rows (https://www.excelbanter.com/excel-programming/376495-select-delete-certain-rows.html)

Eric

select and delete certain rows
 
Does anyone have code for selecting a group of rows, checking one column for
the highest/lowest value of the group, deleting the other rows -- then moving
to the next group?

Just trying to save some time. Thanks!

Tom Ogilvy

select and delete certain rows
 
Sub ABC()
Dim rng As Range, rng1 As Range
Dim lastrow As Long, i As Long
Dim dMax As Double, icol As Long
Dim j as Long
' set column to find max value
icol = 3
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 10 Step -10
Set rng = Cells(i, 1)
Set rng = rng.Offset(-9, 0).Resize(10, 1).EntireRow
Set rng1 = Intersect(rng.EntireRow, Columns(icol))
dMax = Application.Max(rng1)
For j = i To i - 9 Step -1
If Cells(j, icol) < dMax Then
rows(j).Delete
End If
Next j
Next i
End Sub

--
Regards,
Tom Ogilvy


"Eric" wrote:

Does anyone have code for selecting a group of rows, checking one column for
the highest/lowest value of the group, deleting the other rows -- then moving
to the next group?

Just trying to save some time. Thanks!



All times are GMT +1. The time now is 04:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com