1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Sub CopyWorkbookData()
Dim wb As Workbook, wsfromittocopy As Worksheet
Dim strDate0 As String, strDate1 As String
Dim wbReport1 As Workbook, wsReport1 As Worksheet
Dim filepath As String
Dim lngRows As Long, intCols As Integer
Dim rngToCopy As Range, rngOutput As Range
strDate0 = Format(Date - 3, "yyyy.mm.dd")
strDate1 = Format(Date, "yyyy.mm.dd")
Application.ScreenUpdating = False
Set wbReport1 = ActiveWorkbook
Set wsReport1 = wbReport1.Worksheets("Sheet1")
Set rngOutput = wsReport1.Range("$B$2:$CF$2407")
Workbooks.Open Filename:="C:\*****\**** -12102018.xlsm"
'Workbooks.Open "**** -12102018.xlsm"
Set wbFailed = ActiveWorkbook
Set wsFailed = wbFailed.Worksheets("Effects Location")
' Filter the data
With wsFailed
lngRows = .Range("B489").End(xlUp).Row
intCols = .Range("W1").End(xlToLeft).Column
ActiveSheet.Range("$B$2:$CF$2407").AutoFilter Field:=10, Criteria1:="=ALM*" _
, Operator:=xlAnd
'.Range(.Cells(1, 1), .Cells(lngRows, intCols)).AutoFilter _
'Field:=11, Criteria:="=ALM*"
Set rngToCopy = .Range(.Cells(1, 1), .Cells(lngRows, intCols)).SpecialCells(xlCellTypeVisible
'Set rngToCopy = .Range("B2:CF" & .Cells(Rows.Count - 1, "").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
rngToCopy.Copy
rngOutput.PasteSpecial xlPasteValues
End With
' Close the input workbook and set the output range for the next one
wbFailed.Close SaveChanges:=False
Set rngOutput = wsReport1.Range("B489").End(xlUp).Offset(1, 0)
Application.ScreenUpdating = True
End Sub |