Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active July 28, 2024 11:37
Show Gist options
  • Save tueda/7b16b080dc8a683446b10d5416010592 to your computer and use it in GitHub Desktop.
Save tueda/7b16b080dc8a683446b10d5416010592 to your computer and use it in GitHub Desktop.
Lambda function that compares specified cells, returning a score if they match. #excel #lambda
=LAMBDA(answerCell, correctAnswerCell, scoreCell,
IF(answerCell = "",
"",
IF(OR(scoreCell = "", scoreCell = "&"),
"",
LET(Z, LAMBDA(f, LET(g, LAMBDA(x, f(LAMBDA(v, LET(xx, x(x), xx(v))))), g(g))),
countRightAmpersands, Z(LAMBDA(countRightAmpersands, LAMBDA(cell,
LET(right, Offset(cell, 0, 1),
IF(right = "&",
countRightAmpersands(right) + 1,
0
)
)
))),
n, countRightAmpersands(scoreCell),
answerRange, OFFSET(answerCell, 0, 0, 1, n + 1),
correctAnswerRange, OFFSET(correctAnswerCell, 0, 0, 1, n + 1),
IF(OR(answerCellRange = ""),
"",
IF(OR(correctAnswerCellRange = ""),
NA(),
IF(AND(answerCellRange = correctAnswerCellRange),
scoreCell,
0
)
)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment