Name

workbook.AcceptLabelsInFormulas [= setting]

Synopsis

True allows formulas to include range labels as if they were named ranges; False disables the use of labels in formulas. Default is True.

The following code creates some column headings and then makes those headings usable as labels in formulas that display the sum of each column:

' Create two column headings.
[a1] = "col1": [b1] = "col2"
' Add some data.
[a2] = 2: [a3] = 10: [a4] = 12: [a5] = 5
[b2] = 9: [a3] = 17: [b4] = 2: [b5] = 13: [b6] = 29
' Allow labels in formulas.
ThisWorkbook.AcceptLabelsInFormulas = True
' Create labels out of the column headings.
[a1:b1].FormulaLabel = xlColumnLabels
' Use the labels in formulas
[c1] = "=sum(col1)"
[c2] = "=sum(col2)"

If you set AcceptLabelsInFormulas to False in the preceding code, C1 and C2 display an error.

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.