0
votes

enter image description here I want to remove/delete all duplicate rows from 5 columns which have no headers. I have recorded operation in macro and code is here:

Sub Macro11()
Columns("D:D").Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
ActiveSheet.Range("$A$1:$E$8").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5), _
    Header:=xlNo
Range("A1").Select
End Sub

I want above range to be variable as my count of rows will be varying. I have compared column 'C' to remove duplicates. It will be OK to compare each row or cells only from coulmn 'D'.

1
You should look into the principle of lastrow. There are plenty of pieces of code around here that will help you. Then change your ActiveSheet.Range() into : ActiveSheet.Range("$A$1:$E$"&lastrow)Luuklag
See stackoverflow.com/documentation/excel-vba/918/… and stackoverflow.com/a/11169920/4628637 (@Luuklag : it's better if you provide the link! ;) )R3uK
Thanks for letting me know this lastrow links!Samadhan Gaikwad

1 Answers

0
votes

Below code is working fine to me: Sub Macro11() ActiveSheet.Range("A:E").RemoveDuplicates Columns:=4, Header:=xlNo End Sub