• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy Remove Duplicates and Transpose VBA Code Error

Dokat

Member
Hi,

I have below code where i am trying copy row A:A remove duplicates, transpose and paste it to B2. However i am getting Run time error '1004': Application defined or Object defined error message.

Can someone please help me with the issue?

Code:
Sub copytranspose()
Range("A" & Rows.Count).Copy
ActiveSheet.Range("A" & Rows.Count).RemoveDuplicates Columns:=Array(1), _
Header:=xlYes
ActiveSheet.Range(“B2”).PasteSpecial , Transpose:=True
End Sub
 
I dont want to delete the original order in the columns thats why i dont want to remove duplicates before copying.

Thanks
 
I don't think what you want will happen. Maybe someone else has a better idea, but IMO I don't see it.
 
Dokat
From Your the 1st line ...
Code:
Range("A" & Rows.Count).Copy
What would hope that this do?
Have You tried for testing purpose eg
Code:
Range("A" & Rows.Count).Select
Would it select range as You hope?
... and try to continue testing as above row-by-row.
 
Try this:
Code:
Sub copytranspose()
Dim Dict As Object
Dim Arr As Variant
Dim i As Long
Dim LastRow As Long

Set Dict = CreateObject("Scripting.Dictionary")
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Arr = Range("A1:A" & LastRow)
For i = 1 To UBound(Arr, 1)
    Dict(Arr(i, 1)) = 1
Next i

ActiveSheet.Range("B2").Resize(1, _
             UBound(Application.Transpose(Dict.keys))) = Dict.keys
End Sub
 
Back
Top