I have a VBA macro which filters data and copies the results to another sheet. Everything was fine when the football seasons around the world were in full swing, but now with many having completed their interrupted seasons, there is less data. What happens is when there is NO data to transfer, I get an runtime error 1004 message "No cells were found". There are a number of these macros which are called in order, so when this stops, it causes the others to not proceed.
Here is the code:
Can anyone see any issues which cause the macro to fail on the copy line? It happens only when there is NO data to copy
Regards
Here is the code:
VBA Code:
Sub FALAYS()
Dim arr, ws As Worksheet, lc As Long, lr As Long
arr = Array("L.FAL_19_New_Summer2", "L.FA_FAL_3", "L.FAL_19_New_Summer")
Set ws = ActiveSheet
'range from A1 to last column header and last row
lc = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
lr = ws.Cells.Find("*", after:=ws.Range("A1"), LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With ws.Range("A1", ws.Cells(lr, lc))
.HorizontalAlignment = xlCenter
.AutoFilter Field:=1, Criteria1:=arr, Operator:=xlFilterValues
If .Rows.Count - 1 > 0 Then
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy
Else
Exit Sub
End If
End With
Workbooks("Predictology-Reports.xlsx").Sheets("FAL") _
.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
Can anyone see any issues which cause the macro to fail on the copy line? It happens only when there is NO data to copy
Regards