I have some trouble deleting duplicate rows, since the way I have to do it is a kind of hard. Let me explain.
This is what I have (actually I have more than 90,000 rows!)
+-----------+------------------+
| Ref | Sup |
+-----------+------------------+
| 10000-001 | S_LA_LLZ_INOR |
| 10000-001 | S_LA_RADAR_STNFN |
| 10000-001 | S_LA_VOR_LRO |
| 10000-001 | S_LA_DME_LRO |
| 10000-001 | S_LA_DME_INOR |
| 1000-001 | S_LA_GP_INOR |
| 1000-001 | S_LA_LLZ_ITF |
| 1000-001 | S_ZS_LLZ_ITF |
| 1000-002 | S_LA_GP_INOR |
| 1000-002 | S_LA_LLZ_ITF |
+-----------+------------------+
What I have to do is search in column A for duplicates. Then I have to check in column B if the chain of characters after S_LA_
or S_ZS_
are the same. If they are the same. I have to delete the row with the S_LA_
So, in the rows above I would have to delete the row with 1000-001|S_LA_LLZ_ITF
.
I have written a code. It works, but it's painfully slow when working with 10,000+ rows.
Dim LastRowcheck As Long
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim str6 As String
Dim prueba As Integer
Dim prueba1 As Integer
Dim n1 As Long
Dim n3 As Long
Dim colNum As Integer
Dim colNum1 As Integer
Dim iCntr As Long
colNum = WorksheetFunction.Match("Ref", ActiveSheet.Range("1:1"), 0)
colNum1 = WorksheetFunction.Match("Sup",ActiveSheet.Range("1:1"), 0)
With ActiveSheet
LastRowcheck = .Range("A" & .Rows.Count).End(xlUp).Row
For n1 = 2 To LastRowcheck
str1 = Cells(n1, colNum).Value
For n3 = n1 + 1 To LastRowcheck + 1
str2 = Cells(n3, colNum).Value
prueba = StrComp(num1, num2)
If prueba = 0 Then
str3 = Cells(n1, colNum1).Value
str4 = Cells(n3, colNum1).Value
str5 = Right(str3, Len(str3) - 5)
str6 = Right(str4, Len(str4) - 5)
prueba1 = StrComp(str5, str6)
If prueba1 = 0 Then
If StrComp(num3, num4) = 1 Then
Cells(n3, colNum).Interior.ColorIndex = 3
ElseIf StrComp(num3, num4) = -1 Then
Cells(n1, colNum).Interior.ColorIndex = 3
End If
End If
End If
Next n3
Next n1
For iCntr = LastRowcheck To 2 Step -1
If Cells(iCntr, colNum).Interior.ColorIndex = 3 Then
Rows(iCntr).Delete
End If
Next iCntr
End With
I would appreciate any help or guidance you could give me.