I have rows of data from B18 until whatever, there is always data being added on and removed. I want to implement an error check that checks for duplicate rows, until it reaches empty cells. Then I want to shift all the data up so that there isn't just a blank row.
Right now (to start of small) I am just trying to highlight the duplicate data, and I tried a few different things, for example I found a similar code for this on here, but I am getting a type mismatch error. Any help would be appreciated :)
Dim firstRow As Long
Dim lastRow As Long
firstRow = 19
lastRow = 500
For j = firstRow To lastRow
If Range("B" & j & ":H" & j).Interior.Color = RGB(255, 0, 0) Then
Else
For i = j + 1 To lastRow
If Range("B" & i & ":H" & i).Interior.Color = RGB(255, 0, 0) Then
ElseIf Range("B" & i & ":H" & i).Value = Range("B" & j & ":H" & j).Value Then
Range("B" & i & ":H" & i).Interior.Color = RGB(255, 0, 0)
Range("B" & j & ":H" & j).Interior.Color = RGB(255, 0, 0)
End If
Next i
End If
Next j
Update:
I also tried the Worksheet function, and I thought of having nested if loops and comparing each column individually if the previous one matched. However this didn't work as it would compare with all the cells in the column instead of the ones that have cells matching in another column. Ignore the fact that cell C is actually F, I was testing something.
Dim lastRow As Long
Dim rngB As Range
Dim rngC As Range
Dim cB As Range
Dim cC As Range
lastRow = existingSheet.Cells(existingSheet.Rows.Count, "B").End(xlUp).Row + 1
Set rngB = existingSheet.Range("B19:B" & lastRow)
Set rngC = existingSheet.Range("F19:F" & lastRow)
For Each cB In rngB
If Application.WorksheetFunction.CountIf(rngB, cB.Value) > 1 Then
Set cC = existingSheet.Cells(cB.Row, "F")
If Application.WorksheetFunction.CountIf(rngC, cC.Value) > 1 Then
cB.Interior.Color = RGB(255, 0, 0) ' Red color
cC.Interior.Color = RGB(255, 0, 0)
End If
End If
Next cB