Please, read
this MSDN article[
^] to find out what error 1004 means.
Such of addressing:
Sheets("Sheet2")
may not be enough. Imagine, you have 2 workbooks opened. Each of workbook contains
Sheet2
. Does the VBA compiler is able to know what sheet you mean? No!
So, replace this:
Sheets("Sheet1").Range("A1:GC15000").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Sheet2").Range("A1:A2"), CopyToRange:=Sheets("Sheet3").Range("A1:GC15000"), Unique:=False
with:
Sub CopyData()
Dim srcwsh As Worksheet, criwsh As Worksheet, dstwsh As Worksheet
On Error Goto Err_CopyData
Set srcwsh = ThisWorkbook.Worksheets("Sheet1")
Set criwsh = ThisWorkbook.Worksheets("Sheet2")
Set dstwsh = ThisWorkbook.Worksheets("Sheet3")
srcwsh.Range("A1:GC15000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=criwsh.Range("A1:A2"), CopyToRange:=dstwsh.Range("A1"), Unique:=False
Exit_CopyData:
Set srcwsh = Nothing
Set criwsh = Nothing
Set dstwsh = Nothing
Exit Sub
Err_CopyData:
MsgBox Err.Description, vbExclamation, Err.Number
Resume Exit_CopyData
End Sub
For futher details, please see:
Excel VBA Performance Coding Best Practices - Office Blogs[
^]
Handle Run-Time Errors in VBA[
^]
Excel 2010 Performance: Tips for Optimizing Performance Obstructions[
^]