This topic was addressed to some extent in Named Functions - Reduce Formula complexity / Low hanging Fruit to enable functional Programming in Calc, but not directly.
LibreCalc uses the term Macro in a slightly different way than many programming languages, eg C. LibreCalc “Macros” allow one to write VBA functions, using function in the same way as writing a function in C. C also has what it causes a “macro” processor which does not define functions but defines names for textual substitutition. In that sense, it is similar to a named range in LibreCalc. The #define statement in C can be used to define the “macro” called ‘YEAR’ that represents the value ‘2023’ just as in LibreCalc one can define a Macro called ‘YEAR’ that represents the value ‘2023’.
C also allows parameterized “macros”. So for example, I could define the following C macro.
#define LOAD(name) IF(VLOOKUP(name, $‘data-table’.$A$1:$‘data-table’.$B$50, 2, 0) %3 = 1, VLOOKUP(name, $‘data-table’.$A$1:$‘data-table’.$B$50, 2, 0), 0)
Is there a way to do something like that in LibreCalc without going into writing VBA code? The goal is to be able to tke complex equations and express them more simply in the spreadsheet cells. So instead of have a series of cells of this form.
IF(VLOOKUP(“Green”, $‘data-table’.$A$1:$‘data-table’.$B$50, 2, 0) % 3 = 1, VLOOKUP(“Green”, $‘data-table’.$A$1:$‘data-table’.$B$50, 2, 0), 1)
The cell could contain this.
LOAD (“Green”)
Not only does this allow for creating more readable code, it allows one to modify the functionality in one place instead of trying to find hundreds of cells that might be using the LOAD functionality (for example, changing the “remainder” value from 1 to 2). And unlike a VBA, it is just textual substitutions so there is no problem with the values not being available when the spreadhseet is first loaded.
I fnd myself wanting to do this in spreadsheets frequently. I do not see how it can be done with named ranges (in some situations I can create another cell and have the range make a relative reference to that cell but that is not suitable in all situations).
Any ideas on if this is possible in some way? If not, is this a worth candidate for a new feature (I would think not a very burdensome one to implement)?