Evaluating filter function formula.

Herakles

Well-known Member
Joined
Jul 5, 2020
Messages
927
Office Version
  1. 365
Platform
  1. Windows
I am trying to use the EVALUATE function to populate an array with the results of a filter but get a mismatch error.

What am I dong wrong?

This is not a real project, I'm just practising.

Thanks


VBA Code:
Private Sub testIt()
Dim arr() As Variant
    
    arr = Evaluate("IFERROR(INDEX(FILTER(tblNames,tblNames[Group]<>""""), SEQUENCE(3,1,3,1), SEQUENCE(1, COLUMNS(tblNames))), """")")

End Sub

Multi-level Bill Of Materials explosion.xlsm
ABCDEFGH
1NameGroupWinsGroupB
2Item 1C1Rows2
3Item 2A6Start6
4Item 3C4
5Item 4C5Item 1C1
6Item 5A7Item 1C1
7Item 6A9
8Item 7C3
9Item 8A7
10Item 9B4
11Item 10C6
12Item 11B3
13Item 12B5
14Item 13B7
Names
Cell Formulas
RangeFormula
F1F1=CHOOSE(RANDBETWEEN(1,3),"A","B","C")
F2F2=RANDBETWEEN(1,4)
F3F3=RANDBETWEEN(1,7)
E5:G6E5=IFERROR(INDEX(FILTER(tblNames,tblNames[Group]<>""), SEQUENCE($F$2,1,$G$2,1), SEQUENCE(1, COLUMNS(tblNames))), "")
Dynamic array formulas.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try it like
VBA Code:
Private Sub testIt()
Dim arr As Variant
    
    arr = Evaluate("IFERROR(chooserows(FILTER(tblNames,tblNames[Group]<>""""), SEQUENCE(3,1,3,1)), """")")

End Sub
 
Upvote 1
Solution
Try it like
VBA Code:
Private Sub testIt()
Dim arr As Variant
   
    arr = Evaluate("IFERROR(chooserows(FILTER(tblNames,tblNames[Group]<>""""), SEQUENCE(3,1,3,1)), """")")

End Sub

That makes much more sense.

Thanks Fluff
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
For what it's worth, the reason why you're getting a mismatch error is that when the INDEX portion of the formula is evaluated it actually returns a string, not an array as one would expect...

VBA Code:
    Dim arr As Variant
    
    arr = Evaluate("INDEX(FILTER(tblNames,tblNames[Group]<>""""),SEQUENCE(3,1,3,1),SEQUENCE(1,COLUMNS(tblNames)))")
    
    Debug.Print TypeName(arr)

However, we can return an array of values from INDEX like this...

VBA Code:
    Dim arr As Variant
    
    arr = Evaluate("INDEX(FILTER(tblNames,tblNames[Group]<>""""),N(IF(1,SEQUENCE(3,1,3,1))),N(IF(1,SEQUENCE(1,COLUMNS(tblNames)))))")
    
    Debug.Print TypeName(arr)

In any case, @Fluff has provided you with a much more efficient alternative.

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,084
Messages
6,123,021
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top