Last active
October 6, 2023 12:29
-
-
Save NathanAdhitya/9a804ade76964981542616c8b952aac7 to your computer and use it in GitHub Desktop.
A simple Excel FOREACH formula function to iterate over an array. Add this code to Name Manager with the name FOREACH.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lines starting with # are comments, they are not code. | |
# Paste this into Name Manager. Give the name "FOREACH" | |
=LAMBDA( | |
arr; func; offset; | |
IF( | |
offset < COUNTA(arr); | |
VSTACK( | |
func(INDEX(arr; offset)); | |
FOREACH(arr; func; offset+1) | |
); | |
func(INDEX(arr; offset)) | |
) | |
) | |
# Example Usage | |
=FOREACH({1;2;3;4;5}; LAMBDA(x; x); 1) | |
=FOREACH({1;2;3;4;5}; LAMBDA(x; VSTACK(x; IF(MOD(x; 2); "Number above me is even."; "Number above me is odd."))); 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment