I have a worksheet which collects data for football matches and I want to filter for 2 text strings, but eliminate 2 others.
I had previously just used autofilter with 2 criteria to produce anything beginning with LTD or MARIA1, but it just gives too many results which also end with CSP or BTD, so I wanted to try and exclude them, so opted for trying a VBA array
The array I wrote was the following
Here is the entire code
Any thoughts on what is wrong here?
cheers
I had previously just used autofilter with 2 criteria to produce anything beginning with LTD or MARIA1, but it just gives too many results which also end with CSP or BTD, so I wanted to try and exclude them, so opted for trying a VBA array
The array I wrote was the following
arr = Array("LTD*", "MARIA1*", "<>CSP", "<>BTD")
but this falls over giving an RTE 1004 Method 'AutoFilter' of object 'Range' failedHere is the entire code
VBA Code:
Sub LAY_THE_DRAW_DAILY()
Dim arr, ws As Worksheet, lc As Long, lr As Long
arr = Array("LTD*", "MARIA1*", "<>*CSP", "<>*BTD")
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 Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
.DisplayStatusBar = False
.EnableEvents = False
End With
With ws.Range("A1", ws.Cells(lr, lc))
.HorizontalAlignment = xlCenter
.AutoFilter Field:=1, Criteria1:=arr, Operator:=xlFilterValues
If .Rows.Count - 1 > 0 Then
On Error Resume Next
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy
On Error GoTo 0
Else
Exit Sub
End If
End With
Workbooks("Predictology-Reports Football Advisor.xlsm").Sheets("Lay The Draw") _
.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
Any thoughts on what is wrong here?
cheers