I have a problem filtering the date from the first sheet of a workbook and then copying everything in another workbook. In the first part of my code, I'm selecting the workbook I want to work with. When I'm running my code it just copies all the data, without filtering it and i don't know what it's wrong about it.
Sub macro()
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
Dim LastRow As Long
' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook
' get the customer workbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
Sheets("Sheet1").Activate
LastRow = Range("A1").CurrentRegion.Rows.Count
Range("A1:CA" & LastRow).Select
Selection.AutoFilter Field:=39, Criteria1:=Array( _
"0", "1", "2", "3"), Operator:=xlFilterValues
Selection.AutoFilter Field:=12, Criteria1:=">=1/1/2018", _
Operator:=xlFilterValues, _
Criteria2:="<=12/31/2019"
Selection.Copy
Cells.Select
Dim dest As Range
With Workbooks("data.xlsm").Worksheets(3)
Sheets("data").Range("A:CA").ClearContents
Set dest = .Range("A1")
Selection.Copy dest
End With
Selection.AutoFilter
' Close customer workbook
customerWorkbook.Close False
End Sub