Forum Discussion

S_Cubed's avatar
S_Cubed
Copper Contributor
Jan 30, 2023

Data validation using VSTACK with dynamic arrays

I create two distinct dynamic arrays (e.g. dynArray1=OFFSET(rangeName1,0,0,COUNTA(rangeName1),1).  Either of the two dynamic arrays can be used successfully as the source for data validation.  However when using VSTACK to combine the arrays (VSTACK(dynArray1, dynArray2)), the data validation results in the error:  "The source currently evaluates to an error".  

 

However, the cell formula =VSTACK(dynArray1, dynArray2) shows the desired list.

 

What am I missing?

  • S_Cubed You're not missing anything, but DV expects a range formula that returns a range. Dynamic array functions don't work. What you need to do is write the VSTACK formula, let's say in K1. Then, point the DV list to =K1#

    That should work.

  • Patrick2788's avatar
    Patrick2788
    Silver Contributor

    S_Cubed 

    Since you have access to a version of Excel loaded with functions, you could write your dynamic arrays without OFFSET.

     

    An example:

    =LET(names,$A$1:$A$1000,nonblank,COUNTA(names),TAKE(names,nonblank))

     

    TAKE/DROP are also usable inside of Data Validation.

    • S_Cubed's avatar
      S_Cubed
      Copper Contributor
      Patrick,

      Thanks for the example. It appears a bit more intuitive than the OFFSET approach. I'll give that a try.

      How about this.....Dr. Excel Manager, Please create an additional VSTACK function named VSTACKR, perhaps, that returns a Range object.
      • PeterBartholomew1's avatar
        PeterBartholomew1
        Silver Contributor

        S_Cubed 

        Conversely, is there any reason why data validation, like conditional formatting, should not accept Arrays?  There is much in the way of strange legacy behaviours that MS prefer not to touch even though the need may be clear.

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    S_Cubed You're not missing anything, but DV expects a range formula that returns a range. Dynamic array functions don't work. What you need to do is write the VSTACK formula, let's say in K1. Then, point the DV list to =K1#

    That should work.

    • S_Cubed's avatar
      S_Cubed
      Copper Contributor

      Riny_van_Eekelen  I had implemented the solution you describe since I couldn't get data validation to accept the VSTACK output.  However, I have been able to use dynamic arrays successfully as inputs to data validation.  It's only the VSTACK output that has been problematic.

       

      In any case, the solution you have suggested does work.

      • PeterBartholomew1's avatar
        PeterBartholomew1
        Silver Contributor

        S_Cubed 

        As Riny_van_Eekelen suggested, there is a difference between a Range (an area of the worksheet comprising cells and with all sorts of properties such as fill colours and number formats) and an array (a collection of numbers identified by index but with no connection to any particular region of the worksheet). 

         

        INDEX, OFFSET and some new functions such as BYROW or XLOOKUP return references to ranges on the worksheet.  VSTACK and CHOOSEROWS just return arrays of numbers.  This means that data validation and functions such as COUNTIFS work with the first set of functions and not the second.

         

        As Riny says, to make such things work with a dynamic array, you need to output the values to a Range and read them back in again.

Resources