I need some code to find duplicates in Column B, then if found sum Columns I, J & L. Then delete the duplicate rows, only leaving the 1 instance.
I have a button click on Sheet1, and the code needs to run on Sheet4.
I currently have this code, which does the task perfectly, but it only works on the active sheet, i cannot seem to make it work for a different sheet.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False '### Excel wont update its screen while executing this macro. This is a huge performace boost
Dim SumCols() '### declare a second empty array for our sum columns
SumCols() = Array(9, 10, 12) '### the second array stores the columns which should be summed up
'### the next line sets our range for searching dublicates. Starting at cell A2 and ending at the last used cell in column A
Set searchrange = Range([b1], Columns(2).Find(what:="*", after:=[b1], searchdirection:=xlPrevious))
For Each cell In searchrange '### now we start looping through each cell of our searchrange
Set Search = searchrange.Find(cell, after:=cell, lookat:=xlWhole) '### searches for a dublicate. If no dub exists, it finds only itself
Do While Search.Address <> cell.Address '### until we find our starting cell again, these rows are all dublicates
For i = 0 To UBound(SumCols) '### loop through all columns for calculating the sum
'### next line sums up the cell in our starting row and its counterpart in its dublicate row
Cells(cell.Row, SumCols(i)) = CDbl(Cells(cell.Row, SumCols(i))) + CDbl(Cells(Search.Row, SumCols(i)))
Next i '### go ahead to the next column
Search.EntireRow.Delete '### we are finished with this row. Delete the whole row
Set Search = searchrange.Find(cell, after:=cell) '### and search the next dublicate after our starting row
Loop
Next '### from here we start over with the next cell of our searchrange
'### Note: This is a NEW unique value since we already deleted all old dublicates
Application.ScreenUpdating = True '### re-enable our screen updating
End Sub
All help is appreciated!!!!