Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Related to: https://www.reddit.com/r/excel/comments/xj2gy0/comment/itbpe05/?utm_source=share&utm_medium=web2x&context=3
- Lambda function: formulainlineref
- usage: set label_offset to -2 to obtain label two rows to the left.
- LAMBDA(cell,[labels],[brackets],[dp], [label_offset],
- LET(
- use_labels, IF(ISOMITTED(labels), FALSE, labels),
- use_brackets, IF(ISOMITTED(brackets), FALSE, brackets),
- dp_value, IF(ISOMITTED(dp), 2, dp),
- formula_as_text, FORMULATEXT(cell),
- label_offset_value, IF(ISOMITTED(label_offset), -1, -ABS(label_offset)),
- characters_to_put_space_around, {"=","{","}","(",")","+","-","/","*",",","^"},
- add_spaces, REDUCE(formula_as_text,characters_to_put_space_around,LAMBDA(acc,value,SUBSTITUTE(acc,value," "&value&" "))),
- split_by_space, TEXTSPLIT(add_spaces, " "),
- replace_references, MAP(split_by_space, LAMBDA(item,
- LET(
- cell_value, INDIRECT(item),
- rounded_cell_value, IF(ISNUMBER(cell_value), ROUND(cell_value, dp_value),cell_value),
- label, OFFSET(INDIRECT(item), 0, label_offset_value),
- replace_spaces_in_lablels, SUBSTITUTE(label, " ", "_"),
- add_label, IF(use_labels, replace_spaces_in_lablels&"="&rounded_cell_value,rounded_cell_value),
- add_brackets, IF(use_brackets, "["&add_label&"]", add_label),
- IFERROR(add_brackets, item)
- ))
- ),
- join_by_space, TEXTJOIN(" ", TRUE,replace_references),
- remove_spaces, SUBSTITUTE(join_by_space," ",""),
- put_space_after_comma, SUBSTITUTE(remove_spaces,",",", "),
- put_spaces_back_in_labels, SUBSTITUTE(put_space_after_comma,"_"," "),
- put_spaces_back_in_labels))
Advertisement
Add Comment
Please, Sign In to add comment