I was in the process of figuring out some trick to make range's FormulaArray property accept strings >255 chars. Along the way in the interwebs, I came across a link which stated one can indirectly accomplish that by setting a named constant with a value >255 chars (this is apparently possible by concatenating two strings instead of having one long string literal >255 chars) and then pointing the formulaArray at the named constant. In effect:
Names.Add Name:="SOMENAME", RefersToR1C1:="=""" & String(255, "A") & """&""" & String(255, "B") & """"
This seems to work because of the presence of the embedded """&""" character in the middle (it reports the length of the RefersToR1C1 property as 516). I guess it tells the property that I am actually trying to concatenate 2 strings together? I don't quite understand it.
I set out to test this hypothesis (i.e I wanted to first confirm that such concatenations are treated differently by properties not accepting >255 chars) by doing something like this:
Const part1 As String = "{9,9;9,9;"
Const part2 As String = "5,6;7,8}"
Names("SOMENAME").RefersToR1C1 = "=""" & part1 & """&""" & part2 & """"
Set formula_range = ActiveWorkbook.ActiveSheet.Range("D4").Resize(4, 2)
formula_range.FormulaArray = Names("SOMENAME").RefersToR1C1
This works in a way that I wasn't quite expecting. I get a single long string in all 4 rows and 2 columns like this:
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
I wanted to see:
9 9
9 9
5 6
7 8
had I set the FormulaArray property to:
formula_range.FormulaArray = "={9,9;9,9;5,6;7,8}"
I would have got the right output.
How can I do what I want while still using the concatenation trick? Remember, the only reason I am down this road is, in real life, I would need to split a long string into several parts (like part1, part2 above) and tie them together via concatenation to escape the 255 char limitation.
Names.Add Name:="SOMENAME", RefersToR1C1:="=""" & String(255, "A") & """&""" & String(255, "B") & """"
This seems to work because of the presence of the embedded """&""" character in the middle (it reports the length of the RefersToR1C1 property as 516). I guess it tells the property that I am actually trying to concatenate 2 strings together? I don't quite understand it.
I set out to test this hypothesis (i.e I wanted to first confirm that such concatenations are treated differently by properties not accepting >255 chars) by doing something like this:
Const part1 As String = "{9,9;9,9;"
Const part2 As String = "5,6;7,8}"
Names("SOMENAME").RefersToR1C1 = "=""" & part1 & """&""" & part2 & """"
Set formula_range = ActiveWorkbook.ActiveSheet.Range("D4").Resize(4, 2)
formula_range.FormulaArray = Names("SOMENAME").RefersToR1C1
This works in a way that I wasn't quite expecting. I get a single long string in all 4 rows and 2 columns like this:
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
{9,9;9,9;5,6;7,8} {9,9;9,9;5,6;7,8}
I wanted to see:
9 9
9 9
5 6
7 8
had I set the FormulaArray property to:
formula_range.FormulaArray = "={9,9;9,9;5,6;7,8}"
I would have got the right output.
How can I do what I want while still using the concatenation trick? Remember, the only reason I am down this road is, in real life, I would need to split a long string into several parts (like part1, part2 above) and tie them together via concatenation to escape the 255 char limitation.