PDA

View Full Version : Copy unique column values to a new column in a different worksheet



nateblake
05-11-2015, 06:35 AM
I am trying to get the following code to copy all unique string values in in column I of worksheet 5, and copy those unique values to Column A, row 2 of worksheet 3, then unwrap the text. Does anyone know why I get a subscript out of range error??

Sub PrintPartsServices()
Workbooks("Logical_Analysis").Worksheets("Sheet5").Range("A1", Range("A65536").End(xlUp)).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Workbooks("Logical_Analysis").Worksheets("Sheet3").Range("A2"), Unique:=True
Workbooks("Logical_Analysis").Worksheets("Sheet3").Range("A20000:A2").WrapText = False
End Sub

Yongle
05-11-2015, 08:56 AM
It is easier to read the code if inserted inside the code hashtags. Click on the # symbol (next to the speech bubble above where you type a reply)
Anyway, try this small variation to your code


Sub PrintPartsServices()
LastRow = Workbooks("Logical_Analysis").Sheets("Sheet5").Range("A65536").End(xlUp).Row
Workbooks("Logical_Analysis").Worksheets("Sheet5").Range("A1:A" & LastRow).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Workbooks("Logical_Analysis").Worksheets("Sheet3").Range("A2"), Unique:=True
Workbooks("Logical_Analysis").Worksheets("Sheet3").Range("A20000:A2").WrapText = False
End Sub

Yongle
05-12-2015, 01:38 PM
Just noticed that you have included in your code Range("A20000:A2")
Better to stay orthodox and write as Range("A2:A20000")