Cesar87,
Welcome to the MrExcel forum.
What version of Excel and Windows are you using?
Sample raw data (the same color cells represent matches):
Excel 2007
<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="bgcolor: #FCD5B4, align: right"]6[/TD]
[TD="align: center"]5[/TD]
[TD="bgcolor: #99FF33, align: right"]5[/TD]
[TD="align: right"][/TD]
[TD="align: center"]6[/TD]
[TD="bgcolor: #FCD5B4, align: right"]6[/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: right"]7[/TD]
[TD="bgcolor: #99FF33, align: right"]5[/TD]
[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]9[/TD]
[TD="bgcolor: #FFFF00, align: right"]9[/TD]
[TD="bgcolor: #FFFF00, align: right"]9[/TD]
[TD="align: center"]10[/TD]
[TD="bgcolor: #FFFF00, align: right"]10[/TD]
[TD="bgcolor: #FFFF00, align: right"]10[/TD]
[TD="align: center"]11[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]22[/TD]
[TD="align: center"]12[/TD]
[TD="bgcolor: #99FF33, align: right"]13[/TD]
[TD="align: right"][/TD]
[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="bgcolor: #99FF33, align: right"]13[/TD]
[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
</tbody>
Sheet1
After the macro:
Excel 2007
<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]22[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
</tbody>
Sheet1
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
1. Copy the below code
2. Open your NEW workbook
3. Press the keys
ALT +
F11 to open the Visual Basic Editor
4. Press the keys
ALT +
I to activate the Insert menu
5. Press
M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys
ALT +
Q to exit the Editor, and return to Excel
8. To run the macro from Excel press
ALT +
F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Code:
Option Explicit
Sub Cesar87()
' hiker95, 11/05/2013
' http://www.mrexcel.com/forum/excel-questions/737298-how-delete-both-rows-if-cell-value-equal-2-diferent-collums.html
Dim r As Long, lr As Long, fr As Long
lr = Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
For r = lr To 2 Step -1
If Cells(r, 1) <> "" Then
fr = 0
On Error Resume Next
fr = Application.Match(Cells(r, 1), Columns(2), 0)
On Error GoTo 0
If fr = r Then
Rows(r).Delete
ElseIf fr > 0 Then
If r > fr Then
Rows(r).Delete
Rows(fr).Delete
ElseIf fr > r Then
Rows(fr).Delete
Rows(r).Delete
End If
End If
End If
Next r
End Sub
Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension
.xlsm
Then run the
Cesar87 macro.