I have received 2 macros from other users to check a 4th column against the first 3 in excel for duplicates. While they do run they are not working. My spreadsheet has the 4 columns and the data starts in the second row.
Can anyone please advise.
Can anyone please advise.
Code:
[COLOR=#000000]Sub ClearDups()[/COLOR]
[COLOR=#000000] Application.ScreenUpdating = False[/COLOR]
[COLOR=#000000] Dim LastRow As Long[/COLOR]
[COLOR=#000000] LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row[/COLOR]
[COLOR=#000000] Dim phone As Range[/COLOR]
[COLOR=#000000] Dim rng As Range[/COLOR]
[COLOR=#000000] For Each phone In Range("D2:D" & LastRow)[/COLOR]
[COLOR=#000000] For Each rng In Range("A" & phone.Row & ":C" & phone.Row)[/COLOR]
[COLOR=#000000] If phone = Mid(rng, 2, 3) & "-" & Mid(rng, 7, 99) Then[/COLOR]
[COLOR=#000000] phone.ClearContents[/COLOR]
[COLOR=#000000] Exit For[/COLOR]
[COLOR=#000000] End If[/COLOR]
[COLOR=#000000] Next rng[/COLOR]
[COLOR=#000000] Next phone[/COLOR]
[COLOR=#000000] Application.ScreenUpdating = True[/COLOR]
[COLOR=#000000]End Sub
[/COLOR]
[COLOR=#000000]Sub ClearDupesInC() 'cjamps[/COLOR]
[COLOR=#000000]Dim LastC As Long, LastB As Long, i As Long, j As Long, n As Long[/COLOR]
[COLOR=#000000]Application.ScreenUpdating = False[/COLOR]
[COLOR=#000000]LastC = ActiveSheet.Cells(Rows.Count, 3).End(xlUp).Row LastB = ActiveSheet.UsedRange.Rows.Count[/COLOR]
[COLOR=#000000]For n = 3 To 4[/COLOR]
[COLOR=#000000]For i = LastC To 2 Step -1 'if you have no header, go from LastC to 1[/COLOR]
[COLOR=#000000] If Left(Cells(i, n).Value, 1) = 1 Then[/COLOR]
[COLOR=#000000] Cells(i, n).Value = Right(Cells(i, n).Value, Len(Cells(i, n).Value) - 1)[/COLOR]
[COLOR=#000000] End If[/COLOR]
[COLOR=#000000] If Cells(i, n).Value <> "" And _[/COLOR]
[COLOR=#000000]Application.WorksheetFunction.CountIf(Cells(LastC, n), Cells(i, n).Value) > 1 Then[/COLOR]
[COLOR=#000000] Cells(i, n).ClearContents[/COLOR]
[COLOR=#000000] End If[/COLOR]
[COLOR=#000000] If Cells(i, n).Value <> "" Then[/COLOR]
[COLOR=#000000] For j = LastB To 2 Step -1 'if you have no header, go from LastB to 1[/COLOR]
[COLOR=#000000] If (Right(Cells(i, n).Value, 8) = Right(Cells(j, n - 1).Value, 8) And _[/COLOR]
[COLOR=#000000] InStr(2, Left(Cells(j, n - 1).Value, 4), Left(Cells(i, n).Value, n))) _[/COLOR]
[COLOR=#000000] Or (Right(Cells(i, n).Value, 8) = Right(Cells(j, 1).Value, 8) And _[/COLOR]
[COLOR=#000000] InStr(2, Left(Cells(j, 1).Value, 4), Left(Cells(i, n).Value, n))) Then[/COLOR]
[COLOR=#000000] Cells(i, n).ClearContents[/COLOR]
[COLOR=#000000] End If[/COLOR]
[COLOR=#000000] Next j[/COLOR]
[COLOR=#000000] End If[/COLOR]
[COLOR=#000000]Next i[/COLOR]
[COLOR=#000000]Next n[/COLOR]
[COLOR=#000000]Application.ScreenUpdating = True[/COLOR]
[COLOR=#000000]End Sub[/COLOR]