• 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.

VBA filter first then copy data

Cele

Member
Hi,
Please see attached macro.
I have the macro copying data from the Report tab to the DoneTask tab.
But I want it to first, filter column G first by entries with a y on column G on the Report tab.
Then continue doing the macro I have.
The macro in question is copy_done_tasks
Can you help please? Thanks in advance.

Cele
 

Attachments

  • Weekly Updates Report.xlsm
    83.8 KB · Views: 4
Hi,

For the filter you only need this little bit (apply filter->your code->remove filter):
Code:
Sub copy_done_tasks()

Sheets("Report").ListObjects("report").Range.AutoFilter Field:=7, Criteria1:="y"

... Your code here...

Sheets("Report").ShowAllData

End Sub

To copy all the data to DoneTasks, you can also use the following code:
Code:
Sub copy_done_tasks()

    [DoneTasks].Delete
 
    With Sheets("Report")
        .ListObjects("report").Range.AutoFilter Field:=7, Criteria1:="y"
        .Range("report[[Month]:[Notes]]").Copy [DoneTasks]
        .ShowAllData
    End With

End Sub
This will delete all info in the "DoneTasks" Table and copy over the "y" data on "Report". It will also clear the filter when it is done.

On a side note, I would suggest using a Pivot Table for the done tasks... a simple refresh would do basically the same.

Hope this helps.
 
Back
Top