I have a number of VBA macros which autofilter, hide certain columns, then copy the results, minus the header row, to another sheet. By and large they work well, but when there is nothing to copy, there is generally a RE on the line indicating the destination sheet
Here is just one of the macros:
As indicated, if there is nothing to copy, the RE come on this
Any thoughts as to why this occurs and how to amend the macro so it doesn't happen any further?
Cheers
Here is just one of the macros:
VBA Code:
Sub SafeBets()
'
' SafeBets Macro
' This macro will filter for PR, Run Style and Forecast Odds
'
Dim ws As Worksheet, lc As Long, lr As Long
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:=24, Criteria1:="~*", Operator:=xlFilterValues
.AutoFilter Field:=56, Criteria1:="Closer"
.AutoFilter Field:=63, Criteria1:=">=7"
.AutoFilter Field:=64, Criteria1:=">=5"
.AutoFilter Field:=10, Criteria1:=Array("5", "6", "7"), Operator:=xlFilterValues
.AutoFilter Field:=39, Criteria1:=Array("1", "2", "3", "4"), Operator:=xlFilterValues
.AutoFilter Field:=5, Criteria1:=">=60"
.AutoFilter Field:=71, Criteria1:="<>1", Operator:=xlFilterValues
.AutoFilter Field:=69, Criteria1:="<>1", Operator:=xlFilterValues
.AutoFilter Field:=27, Criteria1:="<=20"
If .Rows.Count - 1 > 0 Then
On Error Resume Next
.Columns("C:C").EntireColumn.Hidden = True
.Columns("G:G").EntireColumn.Hidden = True
.Columns("I:I").EntireColumn.Hidden = True
.Columns("K:L").EntireColumn.Hidden = True
.Columns("N:W").EntireColumn.Hidden = True
.Columns("Y:Z").EntireColumn.Hidden = True
.Columns("AB:AK").EntireColumn.Hidden = True
.Columns("AO:AO").EntireColumn.Hidden = True
.Columns("AQ:BC").EntireColumn.Hidden = True
.Columns("BE:BJ").EntireColumn.Hidden = True
.Columns("BM:BP").EntireColumn.Hidden = True
.Columns("BR:BR").EntireColumn.Hidden = True
.Columns("BT:CC").EntireColumn.Hidden = True
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy
On Error GoTo 0
Else
Exit Sub
End If
End With
Workbooks("New Results File Active.xlsm").Sheets("Safe Bets 1") _
.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
As indicated, if there is nothing to copy, the RE come on this
VBA Code:
Workbooks("New Results File Active.xlsm").Sheets("Safe Bets 1") _
.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Any thoughts as to why this occurs and how to amend the macro so it doesn't happen any further?
Cheers