ppark
ppark

Reputation: 1

Excel VBA remove Duplicates using for

I'm trying to RemoveDuplicates for each column EX) removeduplicates for A1:A100, columns=1 / B1:B10-, colums=2......so on

and the boldes codes don't work please help me out

Sub DeleteDulpicates()

Dim i As Integer
Dim X As Integer
Dim Endrow As Long
Dim Endcolumn As Long
Dim sht As Worksheet

Set sht = ActiveSheet

Endrow = Cells.SpecialCells(xlCellTypeLastCell).Row
Endcolumn = sht.Cells.SpecialCells(xlCellTypeLastCell).Column


For i = 1 To Endcolumn
    
***Range(sht.Cells(i, 1), sht.Cells(i, 15000)).RemoveDuplicates Columns:=i, Header:=xlNo***
Next
    
End Sub

Upvotes: 0

Views: 206

Answers (1)

norie
norie

Reputation: 9857

You have row and column the wrong way round in Cells, and if you are removing duplicates from individual columns the Columns argument should be 1.

Option Explicit

Sub DeleteDulpicates()
Dim sht As Worksheet
Dim i As Long
Dim Endcolumn As Long
Dim Endrow As Long

    Set sht = ActiveSheet

    Endrow = Cells.SpecialCells(xlCellTypeLastCell).Row
    Endcolumn = sht.Cells.SpecialCells(xlCellTypeLastCell).Column

    For i = 1 To Endcolumn
        With sht
            .Range(.Cells(1, i), .Cells(Endrow, i)).RemoveDuplicates Columns:=1, Header:=xlNo
        End With
    Next i

End Sub

Upvotes: 1

Related Questions