When I try to run the following macro through a button that I drew on my workbook I get the an error (1004). The macro looks like this:
Sub copy_data()
' Copy incident_id and ticket_id from raw_incidents
Sheets("Raw_Incidents").Select
Range("Raw_incident[[id]:[ticket_id]]").Select
Selection.Copy
Sheets("Report").Select
Range("Report[[incident_id]:[ticket_id]]").Select
ActiveSheet.Paste
' Copy ticket_id from raw_old_ticket_support
Sheets("Raw_Old_Support_Tickets").Select
Range("A5").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Report").Select
' Function found on this page: http://stackoverflow.com/questions/14957994/select-first-empty-cell-in-column-f-starting-from-row-1-without-using-offset
Range("A8:A" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Select
Range(Selection.Cells(1, 2), Selection.Cells(1, 2).End(xlDown)).Select
ActiveSheet.Paste
ActiveSheet.Range("Report[#Tout]").RemoveDuplicates Columns:=2, Header:=xlYes
End Sub
The error is on the last line:
ActiveSheet.Range("Report[#Tout]").RemoveDuplicates Columns:=2, Header:=xlYes
However when I run the macro from the editor, so by pressing the run button, it works fine.
What could be the issue?