EdStockton
New Member
- Joined
- Aug 6, 2014
- Messages
- 47
Hello everyone,
I am attempting to remove duplicates in three columns individually. The data is a trial balance on a sheet entitled TB. I am selecting columns A, B, and C and copying those columns to a new sheet called Criteria. Once I get the columns to Criteria, I need to remove the duplicates in each column individually. It works except for the last column. My trial balance is about 500 rows so for my example shown here I will display only a few rows. My code is as follows:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+z
'
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Sheets(1)
Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Name = "Criteria"
Application.GoTo ActiveWorkbook.Sheets("TB").Cells(1, 1)
ActiveSheet.Range("a1", ActiveSheet.Range("a1").End(xlDown)).Select
Selection.Copy
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 1)
ActiveSheet.Paste
Application.CutCopyMode = False
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 1)
OnlyColumnA
Application.GoTo ActiveWorkbook.Sheets("TB").Cells(1, 2)
ActiveSheet.Range("b1", ActiveSheet.Range("b1").End(xlDown)).Select
Selection.Copy
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 2)
ActiveSheet.Paste
Application.CutCopyMode = False
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 2)
OnlyColumnB
Application.GoTo ActiveWorkbook.Sheets("TB").Cells(1, 3)
ActiveSheet.Range("c1", ActiveSheet.Range("c1").End(xlDown)).Select
Selection.Copy
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 3)
ActiveSheet.Paste
Application.CutCopyMode = False
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 3)
OnlyColumnC
End Sub
Sub OnlyColumnA()
Dim n As Long
n = Cells(Rows.Count, "A").End(xlUp).Row
ActiveSheet.Range("A1:A" & n).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
Sub OnlyColumnB()
Dim m As Long
m = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.Range("B1:B" & m).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
Sub OnlyColumnC()
Dim p As Long
p = Cells(Rows.Count, "C").End(xlUp).Row
ActiveSheet.Range("C1:C" & p).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
When I run this, I still have duplicates in column C. The data I am using is of this nature:
[TABLE="width: 238"]
<tbody>[TR]
[TD]Property[/TD]
[TD]PropType[/TD]
[TD]PropNum[/TD]
[/TR]
[TR]
[TD]Bond0000[/TD]
[TD]Bond[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCP0000[/TD]
[TD]OPCO[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA0000[/TD]
[TD]OPMA[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP0000[/TD]
[TD]CFP[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF0000[/TD]
[TD]RHF[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1001[/TD]
[TD]Bond[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]OPCO1001[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]OPMA1001[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]CFP1001[/TD]
[TD]CFP[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]RHF1001[/TD]
[TD]RHF[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]Bond1005[/TD]
[TD]Bond[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]OPCO1005[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]OPMA1005[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]CFP1005[/TD]
[TD]CFP[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]RHF1005[/TD]
[TD]RHF[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]Bond1007[/TD]
[TD]Bond[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]OPCO1007[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]OPMA1007[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]CFP1007[/TD]
[TD]CFP[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]RHF1007[/TD]
[TD]RHF[/TD]
[TD="align: right"]1007[/TD]
[/TR]
</tbody>[/TABLE]
<strike></strike>
<strike></strike>When the process is finished it should look like this:
[TABLE="width: 234"]
<tbody>[TR]
[TD]Property[/TD]
[TD]PropType[/TD]
[TD]PropNum[/TD]
[/TR]
[TR]
[TD]Bond0000[/TD]
[TD]Bond[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCP0000[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]OPMA0000[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]CFP0000[/TD]
[TD]CFP[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]RHF0000[/TD]
[TD]RHF[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bond1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPCO1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPMA1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CFP1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RHF1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bond1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPCO1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPMA1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CFP1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RHF1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bond1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPCO1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPMA1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CFP1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RHF1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Instead it looks like this:
[TABLE="width: 226"]
<tbody>[TR]
[TD]Property[/TD]
[TD]PropType[/TD]
[TD]PropNum[/TD]
[/TR]
[TR]
[TD]Bond0000[/TD]
[TD]Bond[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCP0000[/TD]
[TD]OPCO[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA0000[/TD]
[TD]OPMA[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP0000[/TD]
[TD]CFP[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF0000[/TD]
[TD]RHF[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCO1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCO1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCO1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
</tbody>[/TABLE]
I would really appreciate your help.
Thanks, Ed
I am attempting to remove duplicates in three columns individually. The data is a trial balance on a sheet entitled TB. I am selecting columns A, B, and C and copying those columns to a new sheet called Criteria. Once I get the columns to Criteria, I need to remove the duplicates in each column individually. It works except for the last column. My trial balance is about 500 rows so for my example shown here I will display only a few rows. My code is as follows:
Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+z
'
Sheets("Sheet1").Select
Sheets("Sheet1").Copy Before:=Sheets(1)
Sheets("Sheet1 (2)").Select
Sheets("Sheet1 (2)").Name = "Criteria"
Application.GoTo ActiveWorkbook.Sheets("TB").Cells(1, 1)
ActiveSheet.Range("a1", ActiveSheet.Range("a1").End(xlDown)).Select
Selection.Copy
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 1)
ActiveSheet.Paste
Application.CutCopyMode = False
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 1)
OnlyColumnA
Application.GoTo ActiveWorkbook.Sheets("TB").Cells(1, 2)
ActiveSheet.Range("b1", ActiveSheet.Range("b1").End(xlDown)).Select
Selection.Copy
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 2)
ActiveSheet.Paste
Application.CutCopyMode = False
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 2)
OnlyColumnB
Application.GoTo ActiveWorkbook.Sheets("TB").Cells(1, 3)
ActiveSheet.Range("c1", ActiveSheet.Range("c1").End(xlDown)).Select
Selection.Copy
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 3)
ActiveSheet.Paste
Application.CutCopyMode = False
Application.GoTo ActiveWorkbook.Sheets("Criteria").Cells(1, 3)
OnlyColumnC
End Sub
Sub OnlyColumnA()
Dim n As Long
n = Cells(Rows.Count, "A").End(xlUp).Row
ActiveSheet.Range("A1:A" & n).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
Sub OnlyColumnB()
Dim m As Long
m = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.Range("B1:B" & m).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
Sub OnlyColumnC()
Dim p As Long
p = Cells(Rows.Count, "C").End(xlUp).Row
ActiveSheet.Range("C1:C" & p).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub
When I run this, I still have duplicates in column C. The data I am using is of this nature:
[TABLE="width: 238"]
<tbody>[TR]
[TD]Property[/TD]
[TD]PropType[/TD]
[TD]PropNum[/TD]
[/TR]
[TR]
[TD]Bond0000[/TD]
[TD]Bond[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCP0000[/TD]
[TD]OPCO[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA0000[/TD]
[TD]OPMA[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP0000[/TD]
[TD]CFP[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF0000[/TD]
[TD]RHF[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1001[/TD]
[TD]Bond[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]OPCO1001[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]OPMA1001[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]CFP1001[/TD]
[TD]CFP[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]RHF1001[/TD]
[TD]RHF[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]Bond1005[/TD]
[TD]Bond[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]OPCO1005[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]OPMA1005[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]CFP1005[/TD]
[TD]CFP[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]RHF1005[/TD]
[TD]RHF[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]Bond1007[/TD]
[TD]Bond[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]OPCO1007[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]OPMA1007[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]CFP1007[/TD]
[TD]CFP[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]RHF1007[/TD]
[TD]RHF[/TD]
[TD="align: right"]1007[/TD]
[/TR]
</tbody>[/TABLE]
<strike></strike>
<strike></strike>When the process is finished it should look like this:
[TABLE="width: 234"]
<tbody>[TR]
[TD]Property[/TD]
[TD]PropType[/TD]
[TD]PropNum[/TD]
[/TR]
[TR]
[TD]Bond0000[/TD]
[TD]Bond[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCP0000[/TD]
[TD]OPCO[/TD]
[TD="align: right"]1001[/TD]
[/TR]
[TR]
[TD]OPMA0000[/TD]
[TD]OPMA[/TD]
[TD="align: right"]1005[/TD]
[/TR]
[TR]
[TD]CFP0000[/TD]
[TD]CFP[/TD]
[TD="align: right"]1007[/TD]
[/TR]
[TR]
[TD]RHF0000[/TD]
[TD]RHF[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bond1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPCO1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPMA1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CFP1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RHF1001[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bond1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPCO1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPMA1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CFP1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RHF1005[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bond1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPCO1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]OPMA1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CFP1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]RHF1007[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Instead it looks like this:
[TABLE="width: 226"]
<tbody>[TR]
[TD]Property[/TD]
[TD]PropType[/TD]
[TD]PropNum[/TD]
[/TR]
[TR]
[TD]Bond0000[/TD]
[TD]Bond[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCP0000[/TD]
[TD]OPCO[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA0000[/TD]
[TD]OPMA[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP0000[/TD]
[TD]CFP[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF0000[/TD]
[TD]RHF[/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCO1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF1001[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCO1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF1005[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]Bond1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPCO1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]OPMA1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]CFP1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
[TR]
[TD]RHF1007[/TD]
[TD][/TD]
[TD]0000[/TD]
[/TR]
</tbody>[/TABLE]
I would really appreciate your help.
Thanks, Ed
Last edited: