Created
June 2, 2016 18:52
-
-
Save erajanraja24/dfe65c2a34bb9d5ff93c6da87c301d92 to your computer and use it in GitHub Desktop.
VBA to remove duplicates in an unknown range and unknown/dynamic columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub check() | |
'Determing the last column | |
LastCol = ThisWorkbook.Sheets(1).UsedRange.Columns.Count | |
'Determining the last row | |
LastRow = ThisWorkbook.Sheets(1).UsedRange.Rows.Count | |
'Determining the Range | |
Set Rng = ThisWorkbook.Sheets(1).Range(Cells(2, 1), Cells(LastRow, LastCol)) | |
'find the number of columns and enter into the array | |
ReDim varArray(LastCol - 1) | |
'ReDim varArray1(Application.WorksheetFunction.CountA(rng)) | |
Index = 0 | |
'loop through range and load values to the array | |
Do Until Index > LastCol - 1 | |
varArray(Index) = Index + 1 | |
Index = Index + 1 | |
Loop | |
'remove duplicates | |
Rng.RemoveDuplicates Columns:=(varArray), Header:=xlNo | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It worked.
Thank you.