aqwa
aqwa

Reputation: 3

Removing Duplicates Issue

I'm trying to remove duplicates of rows with this code:

    Sub removeDuplicates()
'
' Macro7 Macro

'Workbooks("Tester.xlsm").Worksheets(1).Range("A1", Range("F1").End(xlDown)).removeDuplicates Columns:=Array(1, 2), Header:=xlYes
Set Rng = Range("A1", Range("F1").End(xlDown))
    Workbooks("Tester").Worksheets(1).Rng.removeDuplicates Columns:=Array(1, 2), Header:=xlYes

End Sub

However, it gives me a runtime 1004 error, what am I doing wrong? Is there a solution to this? Btw the commented code does not work also, it gives back the same error message

Upvotes: 0

Views: 49

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49395

The Worksheet class doesn't provide the Rng property. It seems you are trying to re-use the variable Rng defined in the code, but it is not yet assigned until the line is finished running. Use the Worksheet.Range property instead:

Set Rng = Workbooks("Tester").Worksheets(1).Range("A1", Workbooks("Tester").Worksheets(1).Range("F1").End(xlDown))
Rng.removeDuplicates Columns:=Array(1, 2), Header:=xlYes

Upvotes: 1

Related Questions