kenchristensen11
Board Regular
- Joined
- Oct 12, 2016
- Messages
- 52
Hello,
I have the existing code, and it basically copies and pastes values from a data table and then keeps all the columns I need by header name. I have duplicates removed based on Column 3, but sometimes the original data is not sorted the same. Is there a code where it searches by column header (in this case, "EMP_SSN"), then removes duplicates from that column only?
Thanks
I have the existing code, and it basically copies and pastes values from a data table and then keeps all the columns I need by header name. I have duplicates removed based on Column 3, but sometimes the original data is not sorted the same. Is there a code where it searches by column header (in this case, "EMP_SSN"), then removes duplicates from that column only?
Thanks
Code:
Sheets("TV").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Working File"
Range("A1").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = "PROD_NAME" _
Or ActiveCell.Value = "EMP_NAME" _
Or ActiveCell.Value = "EMP_SSN" _
Or ActiveCell.Value = "CORP_NAME" _
Or ActiveCell.Value = "CORP_TAX_ID" _
Or ActiveCell.Value = "AFFILIATION_ID" _
Or ActiveCell.Value = "JOB_TITLE" _
Or ActiveCell.Value = "ADDR1" _
Or ActiveCell.Value = "ADDR2" _
Or ActiveCell.Value = "CITY" _
Or ActiveCell.Value = "STATE" _
Or ActiveCell.Value = "ZIP" _
Or ActiveCell.Value = "WORK_TX_REGION" _
Or ActiveCell.Value = "BIRTH_DATE" Then
ActiveCell.Offset(0, 1).Select
Else
ActiveCell.EntireColumn.Select
Selection.Delete Shift:=xlToLeft
Selection.End(xlUp).Select
End If
Loop
Dim Lastrow As Long
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Font.Bold = True
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.AutoFilter
ActiveWindow.SmallScroll Down:=-15
Range(Selection, Selection.End(xlToRight)).Select
Selection.Columns.AutoFit
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Range("$A$1:$N$3000").RemoveDuplicates Columns:=3, Header:=xlYes
Range("A1").Select
Last edited by a moderator: