Share via

Issue with VBA array Filter function - bug?

Anonymous
2017-12-11T11:12:20+00:00

Hi there,

I am running into some issues while using VBA its 'Filter' function in a one dimensional array. It seems that only the first element that matches the 'Match' value is returned and not the subsequent one's.

To given an example, when running the code below, the second debug call return '1' but it should return '2'       

Function FilterAnArray()

Dim names As Variant

names = Array("Ann Smith", "Barry Jones", "John Smith", "Stephen Brown", "Wilfred Cross")

Debug.Print UBound(names)

Dim smithNames As Variant

smithNames = Filter(names, "Smith")

Debug.Print UBound(smithNames)

End Function

Version information e.t.c.

I am running Excel 2016, version 16.0.8730.2046 - 64-bit. 

Any help with this issue is much appreciated!

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2017-12-14T20:33:46+00:00

    Hi,

    Ubound(names)=4 (0/1/2/3/4) 5 items

    UBound(smithNames)=1 (0/1) 2 items

    it's correct

    first item is 

    smithNames(0)="Ann Smith"

    Was this answer helpful?

    0 comments No comments