I have a list of non conformities appeared in different time with different products. I need to find out similar problems. I already made sorting
Now I need to get new sheet with similar rows with similar values in Product, Non coformity and date.
To get it I used following code, but not sure that it's correct approach:
' Look for similar non conformities >2
Sheets.Add.Name = "Result"
Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim CurrentRow As Long, Lastrow As Long, Lastrow2 As Long, k As Long
Set wb = ActiveWorkbook
Set ws = wb.Sheets("DuplicateRecords") 'Sheet where I have filtered result
Set ws2 = wb.Sheets("Result") ' Resulting sheet
CurrentRow = 2
Lastrow = ws.Range("V" & Rows.Count).End(xlUp).Row
For k = CurrentRow To Lastrow
If ws.Range("G" & CurrentRow).Value2 = ws.Range("G" & CurrentRow + 1).Value2 And _
ws.Range("V" & CurrentRow).Value2 = ws.Range("V" & CurrentRow + 1).Value2 And _
ws.Range("T" & CurrentRow).Value2 = ws.Range("T" & CurrentRow + 1).Value2 Then
Lastrow2 = ws2.Range("A" & Rows.Count).End(xlUp).Row
ws2.Range("A" & Lastrow2 + 1).Value2 = ws.Range("A" & CurrentRow).Value2
ws2.Range("B" & Lastrow2 + 1).Value2 = ws.Range("B" & CurrentRow).Value2
ws2.Range("C" & Lastrow2 + 1).Value2 = ws.Range("C" & CurrentRow).Value2
ws2.Range("D" & Lastrow2 + 1).Value2 = ws.Range("D" & CurrentRow).Value2
End If
CurrentRow = CurrentRow + 1
Next k



Another non-VBA solution would be to use
Power Query(akaGet & Transform), available in Windows Excel 2010+ and Microsoft 365 (Windows or Mac)To use Power Query
Data => Get&Transform => from Table/RangeHome => Advanced EditorApplied Stepsto understand the algorithmM Code
Edit
If you must use
VBA, here is a routine which, by using Collections, Dictionary and VBA Arrays, should execute quite rapidly -- 5-10 times quicker than referring to the worksheet at each step