Quote Originally Posted by p24leclerc View Post
to Event21,
something is wrong in your MAX function.
WorksheetFunction.Max(r.Offset(-1, 1).Resize(2))

Resize and Offset should be variable too.

This modification seems to work:
Sub test()
Dim lastRow&, r As Range, startrow, midrow
With ActiveSheet
    .UsedRange.AutoFilter Field:=1, Criteria1:="=*dup*"
    startrow = 2
    midrow = 2
    lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    For Each r In .Range("a2:a" & lastRow).SpecialCells(xlCellTypeVisible)
      midrow = r.Row
        r.Offset(1).EntireRow.Insert
        'Max function does not work properly
        r.Offset(1).Resize(, 2).Value = Array(r.Value & "_max", WorksheetFunction.Max(r.Offset(-(midrow - startrow + 1), 1).Resize(midrow - startrow + 1)))
    startrow = r.Offset(3).Row
    Next
    .UsedRange.AutoFilter
End With
End Sub
I really learned something with your code Event21. I was looking for something like this, but it seems to be out of reach for me.
Thanks
so if you run your modified code, you will get;
Labels	Data
MW-01	10
MW-02	20
MW-03	10
MW-04	15
MW-04-dup	25
MW-04-dup_max	20
MW-05	30
MW-06	45
MW-07	2
MW-08	50
MW-09	50
MW-10	55
MW-10-dup	48
MW-10-dup_max	55
MW-11	43
the sample from -P. on this red portion = MW-04-dup 25

If I have spaces in my dataset, meaning blank rows between groups, will this cause problems?
no as long as the space row is not covered by the two cells above the "dup" cell

let us see the test results from -P.

event