# NEED HELP with Macros!!

##### New Member
I have a project which is due tomorrow, end of day, so I'm panicing at this point. Any help would be greatly appreciated.

I need the macro to find duplicate entries in 2 separate columns (last name, first name) and delete the entry with those with a lower value in a third column.

For example,
Column A = Last Name
Column B = First Name
Column R = Final test result

So basically people who have taken a test more than once, only their highest mark will count, which is why I need to delete the lower test value.

If it matters, some people have also taken the test three times.

### Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This will do the job

Code:
``````Option Explicit

Public Const deli = "..."

Sub main()

Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(1)
Dim lastRow As Long
lastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
Dim iarr As Variant

extr arr:=iarr, ws:=ws, lastRow:=lastRow
remov arr:=iarr, ws:=ws, i:=lastRow

End Sub

Sub extr(ByRef arr As Variant, ByRef ws As Worksheet, ByVal lastRow)

Dim i, j
ReDim arr(lastRow - 1)
For i = 2 To lastRow
arr(i - 2) = ws.Range("A" & i).Value & deli & ws.Range("B" & i).Value
Next i

ReDim Preserve arr(UBound(arr))
For i = LBound(arr) To UBound(arr)
For j = LBound(arr) To UBound(arr)
If arr(i) = arr(j) Then
If ws.Range("R" & i + 2).Value > ws.Range("R" & j + 2).Value Then
arr(i) = j + 2
ElseIf ws.Range("R" & i + 2).Value < ws.Range("R" & j + 2).Value Then
arr(i) = i + 2
End If
End If
Next j
Next i
End Sub

Sub remov(ByRef arr As Variant, ByRef ws As Worksheet, ByVal i As Long)
For i = UBound(arr) To LBound(arr) Step -1
If IsNumeric(arr(i)) And arr(i) <> 0 Then
ws.Rows(arr(i) & ":" & arr(i)).Select
Selection.Delete shift:=xlUp
End If
Next i
End Sub``````

Thank you so much! Such a great help!

Replies
6
Views
378
Replies
2
Views
289
Replies
7
Views
333
Replies
0
Views
293
Replies
0
Views
185

1,217,474
Messages
6,136,860
Members
450,028
Latest member
CHlEFS47

### 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.

### Which adblocker are you using?

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

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