dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
Firstly: all this is for a dynamic table called StockListTable.
I have a Column (Header = Owner) containing numbers representing customer numbers (1 to 150 plus 998 and 999).
I wish to filter out the following customer numbers---0, 27, 72, 84, 100, 998 and 999---thus leaving all other customer numbers.
I can use autofilter to include all customer numbers using an array:
However, I can only include about 150 values in the array and no more; hence, as customers are added, this option will fail.
I have tried to use an array to specify "Does not contain":
However, VBAeditor gives the error message: Run-time error: '2': Subscript out of range.
I have tried an alternative way of filtering using arrays:
VBeditor outputs this error: Run-time error '1004': AutoFilter method or Range class failed.
Would anybody be willing to help me modify the code to allow it to filter out multiple customer numbers?
Kind regards,
Doug.
Firstly: all this is for a dynamic table called StockListTable.
I have a Column (Header = Owner) containing numbers representing customer numbers (1 to 150 plus 998 and 999).
I wish to filter out the following customer numbers---0, 27, 72, 84, 100, 998 and 999---thus leaving all other customer numbers.
I can use autofilter to include all customer numbers using an array:
Code:
ActiveSheet.Range("StockListTable[Owner]").AutoFilter Field:=4, Criteria1:=[COLOR=#0000cd][B]Array("1", "2", "n", etc)[/B][/COLOR], Operator:=xlFilterValues
However, I can only include about 150 values in the array and no more; hence, as customers are added, this option will fail.
I have tried to use an array to specify "Does not contain":
Code:
ActiveSheet.Range("StockListTable[Owner]").AutoFilter Field:=4, Criteria1:=[COLOR=#0000ff][B]Array("<>0", "<>27", "<>72", etc)[/B][/COLOR], Operator:=xlFilterValues
However, VBAeditor gives the error message: Run-time error: '2': Subscript out of range.
I have tried an alternative way of filtering using arrays:
Code:
Sub ArrayFilter()
Dim lo As Excel.ListObject
Dim CustNumbers As Variant
Set lo = ActiveWorkbook.Worksheets("Stock List").ListObjects("StockListTable")
CustNumbers = [COLOR=#0000ff][B]Array("<>0", "<>027", "<>72")[/B][/COLOR]
lo.DataBodyRange.AutoFilter Field:=4, _
Criteria1:=CustNumbers, Operator:=xlFilterValues
End Sub
VBeditor outputs this error: Run-time error '1004': AutoFilter method or Range class failed.
Would anybody be willing to help me modify the code to allow it to filter out multiple customer numbers?
Kind regards,
Doug.