Hi Everyone !!
I have written a code to copy values from one column and then pasting without duplicate values on another column in the same sheet. I am having issues because instead of deleting the duplicate values only its is removing the entire row where those duplicate entries are found. I am basically copying all of column G and column K, removing the duplicates, and pasting those unique values of column G on column Q and those unique values of column K on column Y. The purpose is to do a SumIf calclation that I have placed on the columns next to where the unique values would be found. Please help me if you can !!! Here is my code up to now:
Sub CopyUnique()
Dim LR As Long, i As Long, LR2 As Long, s As Long
Sheets("Verify Dispatch").Range("Q3:Q1000").ClearContents
Sheets("Verify Dispatch").Range("Y3:Y1000").ClearContents
Sheets("Verify Dispatch").Range("R4:X1000").ClearContents
Sheets("Verify Dispatch").Range("Z4:AF1000").ClearContents
With Sheets("Verify Dispatch")
LR = .Range("G" & Rows.Count).End(xlUp).Row
.Range("G3:G" & LR).Copy Destination:=Sheets("Verify Dispatch").Range("Q" & Rows.Count).End(xlUp).Offset(1)
LR2 = .Range("K" & Rows.Count).End(xlUp).Row
.Range("K3:K" & LR2).Copy Destination:=Sheets("Verify Dispatch").Range("Y" & Rows.Count).End(xlUp).Offset(1)
For i = LR To 2 Step -1
If WorksheetFunction.CountIf(.Columns("Q"), .Range("Q" & i).Value) > 1 Then .Rows(i).Delete
On Error Resume Next
.Columns("Q").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
Next i
For s = LR2 To 2 Step -1
If WorksheetFunction.CountIf(.Columns("Y"), .Range("Y" & s).Value) > 1 Then .Rows(s).Delete
On Error Resume Next
.Columns("Y").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
Next s
End With
End Sub
THANK YOU !!
I have written a code to copy values from one column and then pasting without duplicate values on another column in the same sheet. I am having issues because instead of deleting the duplicate values only its is removing the entire row where those duplicate entries are found. I am basically copying all of column G and column K, removing the duplicates, and pasting those unique values of column G on column Q and those unique values of column K on column Y. The purpose is to do a SumIf calclation that I have placed on the columns next to where the unique values would be found. Please help me if you can !!! Here is my code up to now:
Sub CopyUnique()
Dim LR As Long, i As Long, LR2 As Long, s As Long
Sheets("Verify Dispatch").Range("Q3:Q1000").ClearContents
Sheets("Verify Dispatch").Range("Y3:Y1000").ClearContents
Sheets("Verify Dispatch").Range("R4:X1000").ClearContents
Sheets("Verify Dispatch").Range("Z4:AF1000").ClearContents
With Sheets("Verify Dispatch")
LR = .Range("G" & Rows.Count).End(xlUp).Row
.Range("G3:G" & LR).Copy Destination:=Sheets("Verify Dispatch").Range("Q" & Rows.Count).End(xlUp).Offset(1)
LR2 = .Range("K" & Rows.Count).End(xlUp).Row
.Range("K3:K" & LR2).Copy Destination:=Sheets("Verify Dispatch").Range("Y" & Rows.Count).End(xlUp).Offset(1)
For i = LR To 2 Step -1
If WorksheetFunction.CountIf(.Columns("Q"), .Range("Q" & i).Value) > 1 Then .Rows(i).Delete
On Error Resume Next
.Columns("Q").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
Next i
For s = LR2 To 2 Step -1
If WorksheetFunction.CountIf(.Columns("Y"), .Range("Y" & s).Value) > 1 Then .Rows(s).Delete
On Error Resume Next
.Columns("Y").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
Next s
End With
End Sub
THANK YOU !!