PDA

View Full Version : Solved: Problem with compare and deleting in 3 column



parscon
03-10-2012, 02:38 PM
I have a Problem .
I have this code , this code will compare 3 column A-B-C and if find a duplicated in row will be deleted , but whe in have word+number it will not work . how can i fix it ?






Sub Delete()

Dim i As Long
Dim dCol As Long
Dim lrow As Long

'Column to check first (A)
dCol = 1

'Get last row of data, Col A
lrow = Cells(65536, dCol).End(xlUp).Row

'Check each row: lastrow to row 2
For i = lrow To 2 Step -1

'If Col A AND Col B and Col C are match
If Cells(i, 1) = Cells(i - 1, 1) And Cells(i, 2) And Cells(i, 3) = Cells(i - 1, 3) Then


'Delete dupe row
Cells(i, 1).EntireRow.Delete
End If
Next i
End Sub

jonhaus
03-10-2012, 08:19 PM
Try something like this. Note that as the code you provided this macro will only delete a duplicate if it is in the proceeding row. Enjoy.

Sub Delete()

Dim r As Integer

'Start with row 2
r = 2

'continue until a blank cell is encountered
Do Until Len(Cells(r, 1)) = 0

'If Col A AND Col B and Col C match previous row
If Cells(r, 1) = Cells(r - 1, 1) And Cells(r, 2) = Cells(r - 1, 2) And Cells(r, 3) = Cells(r - 1, 3) Then
'Delete dupe row
Cells(r, 1).EntireRow.Delete

Else
'proceed to next row
r = r + 1
End If
Loop
End Sub

parscon
03-11-2012, 04:03 AM
Thank you for your help .