SimplyCole
New Member
- Joined
- Apr 8, 2015
- Messages
- 5
Good day,
I am working on a Macro for one of my coworkers that should delete duplicate rows based on Social Security Numbers in Column A. Right now, I have it deleting the duplicate row, but I need to add a condition that if one (or both) duplicate rows contain data outside of Column A's SSN, then leave the rows. I need it to ONLY delete duplicate Rows if there is no data outside of the duplicate SSN's.
My thinking was to possibly check Column B, cell to the right of the duplicate SSN to see if that contained any data; if it did, then leave that duplicate SSN in the worksheet. If it did not, go ahead and delete that duplicate SSN.
Any help would be GREATLY appreciated, as I am a novice when it comes to VBA.
For reference, here is the code I am working with:
I placed the .csv document I am working on here: http://itscol.es/excel/401k to principal.csv as well as the Personal.xlsb I have here: http://itscol.es/excel/Personal.xlsb
I appreciate any help you lovely folks can offer.
Thank you,
Cole
I am working on a Macro for one of my coworkers that should delete duplicate rows based on Social Security Numbers in Column A. Right now, I have it deleting the duplicate row, but I need to add a condition that if one (or both) duplicate rows contain data outside of Column A's SSN, then leave the rows. I need it to ONLY delete duplicate Rows if there is no data outside of the duplicate SSN's.
My thinking was to possibly check Column B, cell to the right of the duplicate SSN to see if that contained any data; if it did, then leave that duplicate SSN in the worksheet. If it did not, go ahead and delete that duplicate SSN.
Any help would be GREATLY appreciated, as I am a novice when it comes to VBA.

For reference, here is the code I am working with:
Code:
Public Sub DeleteDuplicateRows()
' This macro will delete all duplicate rows which reside under
' the first occurrence of the row.
' Use the macro by selecting a column to check for duplicates
' and then run the macro and all duplicates will be deleted, leaving
' the first occurrence only.
Dim R As Long
Dim N As Long
Dim V As Variant
Dim Rng As Range
On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set Rng = Application.Intersect(ActiveSheet.UsedRange, _
ActiveSheet.Columns(ActiveCell.Column))
Application.StatusBar = "Processing Row: " & Format(Rng.Row, "#,##0")
N = 0
For R = Rng.Rows.Count To 2 Step -1
If R Mod 500 = 0 Then
Application.StatusBar = "Processing Row: " & Format(R, "#,##0")
End If
V = Rng.Cells(R, 1).Value
If V = vbNullString Then
If Application.WorksheetFunction.CountIf(Rng.Columns(1), vbNullString) > 1 Then
Rng.Rows(R).EntireRow.Delete
N = N + 1
End If
Else
If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then
Rng.Rows(R).EntireRow.Delete
N = N + 1
End If
End If
Next R
EndMacro:
Application.StatusBar = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Duplicate Rows Deleted: " & CStr(N)
End Sub
I placed the .csv document I am working on here: http://itscol.es/excel/401k to principal.csv as well as the Personal.xlsb I have here: http://itscol.es/excel/Personal.xlsb
I appreciate any help you lovely folks can offer.

Thank you,
Cole