Script to - subtotal and remove duplicates with lower subtotal

derek.hughes

Board Regular
Joined
Mar 16, 2012
Messages
53
This sheet has thousands of rows of data, but this is a "snippet" of what I am trying to accomplish.

NameBargain UnitPay ClassFTE
John Doe220150.05
John Doe220150.10
John Doe220150.10
John Doe220200.50
John Doe220200.25

<tbody>
</tbody>

I have employees that work in the same bargaining units, but under different pay classes. I essentially want a script that will:
  • Figure out the Sum of the FTE, by Pay Class (Subtotal)
  • Remove duplicates, leaving behind the rows with the LARGEST SUM of FTE

In the example above it would leave behind the last two rows - by the way I do not need it to leave behind the summed total of the FTE, I just used that to explain how I want the Macro to decide which rows to remove.

Thanks!

Derek
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
COPY DATA IN SHEET 1 TO SHEET 2 TO PRESEVE ORIGINAL CONFIGURATION


for subtotal problem the following macrto will work
Code:
Sub test()
Dim rdata As Range
Worksheets("sheet1").Cells.Clear
Worksheets("sheet2").Cells.Copy Worksheets("sheet1").Range("A1")
Worksheets("sheet1").Activate
Set rdata = Range("A1").CurrentRegion
    rdata.RemoveSubtotal
    rdata.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
            
End Sub
but "remove duplicate leaving behid te rows with largest sum of FTE" this is not clear. how the last two rows give the largest sum (the operate word"sum" is cofusig").if individual FTE is considered fouth row to be retained.
assuing fourth row only is retained then presume original subtotal of 1.0 is to be retained.


explian with examples
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top