Guest User

formulainlineref

a guest
Oct 30th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | Source Code | 0 0
  1. Related to: https://www.reddit.com/r/excel/comments/xj2gy0/comment/itbpe05/?utm_source=share&utm_medium=web2x&context=3
  2.  
  3. Lambda function: formulainlineref
  4. usage: set label_offset to -2 to obtain label two rows to the left.
  5.  
  6.  
  7. LAMBDA(cell,[labels],[brackets],[dp], [label_offset],
  8. LET(
  9. use_labels, IF(ISOMITTED(labels), FALSE, labels),
  10. use_brackets, IF(ISOMITTED(brackets), FALSE, brackets),
  11. dp_value, IF(ISOMITTED(dp), 2, dp),
  12. formula_as_text, FORMULATEXT(cell),
  13. label_offset_value, IF(ISOMITTED(label_offset), -1, -ABS(label_offset)),
  14. characters_to_put_space_around, {"=","{","}","(",")","+","-","/","*",",","^"},
  15. add_spaces, REDUCE(formula_as_text,characters_to_put_space_around,LAMBDA(acc,value,SUBSTITUTE(acc,value," "&value&" "))),
  16. split_by_space, TEXTSPLIT(add_spaces, " "),
  17. replace_references, MAP(split_by_space, LAMBDA(item,
  18. LET(
  19. cell_value, INDIRECT(item),
  20. rounded_cell_value, IF(ISNUMBER(cell_value), ROUND(cell_value, dp_value),cell_value),
  21. label, OFFSET(INDIRECT(item), 0, label_offset_value),
  22. replace_spaces_in_lablels, SUBSTITUTE(label, " ", "_"),
  23. add_label, IF(use_labels, replace_spaces_in_lablels&"="&rounded_cell_value,rounded_cell_value),
  24. add_brackets, IF(use_brackets, "["&add_label&"]", add_label),
  25. IFERROR(add_brackets, item)
  26. ))
  27. ),
  28. join_by_space, TEXTJOIN(" ", TRUE,replace_references),
  29. remove_spaces, SUBSTITUTE(join_by_space," ",""),
  30. put_space_after_comma, SUBSTITUTE(remove_spaces,",",", "),
  31. put_spaces_back_in_labels, SUBSTITUTE(put_space_after_comma,"_"," "),
  32. put_spaces_back_in_labels))
Advertisement
Add Comment
Please, Sign In to add comment