Hi I have been working on the following code, basically it should filter against two columns across multiple worksheets and dump the results into anther worksheet. The issue that I have is it only appears to post a single row off the final sheet in the Array and I can not understand what is wrong. Any help would be appreciated
VBA Code:
Sub OverdueUpdate()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim CopyRng As Range
Dim lr As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Clears exiting content
Worksheets("Overdue Items").Range("B8:F29").ClearContents
Set DestSh = ActiveWorkbook.Worksheets("Overdue Items")
'Looks through the sheets named and copies data to overdue
For Each sh In ActiveWorkbook.Sheets(Array("Due Diligence", "Pre-Filing", "Product Development", "CAPM", "Operations"))
'Find the last rows with data
Last = LastRow(DestSh)
Last2 = LastRow(sh)
'Filter
With sh.Range("B5:F" & Last2)
.AutoFilter Field:=1, Criteria1:="<100%"
.AutoFilter Field:=3, Criteria1:="<FilterToday"
End With
'Fill in the range that you want to copy
Set CopyRng = sh.Range("B5:F" & Last2 & lr).SpecialCells(xlCellTypeVisible)
With sh.Range("B5:F" & Last2)
.AutoFilter Field:=1
.AutoFilter Field:=3
End With
With CopyRng
DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With
Next
End Sub
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("b8"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function