简体   繁体   中英

VBA FormulaArray range class error when the Characters are less than 255

The VBA .FormulaArray seems to have a problem with my range. I've read that it can't handle over 255 characters, but mine is only about 108, but I could be understanding it wrong.

It gives an

Error 1004:
Unable to set FormulaArray property of the Range class.

I've tried leaving the formula in the table column and let it automatically populate when the table is filled with the Macro, but the problem is that the Index array table doesn't exist yet before the Macro starts running.

Also tried leaving it as text and then changing the column to "general" but it doesn't work. And I know it will create a problem changing it to an array formula this way as well.

This is the code I'm using:

With wsOutdated.ListObjects("Table_Outdated_Stock_Counts")
        .ListColumns("Ranging").DataBodyRange.NumberFormat = "General"
        .ListColumns("Ranging").DataBodyRange.FormulaArray = "=INDEX(Table_DispoData[[Class]],MATCH([@Article]&[@Site],Table_DispoData[Article]&Table_DispoData[Site],0),1)"
    End With

I need the table column to populate automatically with the array formula. It works for other columns(they are not array formulas though and only need to match a single value).

Maybe you could try:

.ListColumns("Ranging").DataBodyRange.Cells(1, 1).FormulaArray = "=INDEX(Table_DispoData[[Class]],MATCH([@Article]&[@Site],Table_DispoData[Article]&Table_DispoData[Site],0),1)"

Instead of :

.ListColumns("Ranging").DataBodyRange.FormulaArray = "=INDEX(Table_DispoData[[Class]],MATCH([@Article]&[@Site],Table_DispoData[Article]&Table_DispoData[Site],0),1)"

and see if it works for you!

Explanation:

Your code is trying to write Array formula to multiple cells simultaneously which is not allowed. If you try to do this in Excel then it will return an error "Multi-cell array formulas aren't allowed in tables".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM