This formula combines the two ranges provided (B5:C12 and E5:F10), by appending the second range to the right of the first range. The result is returned as an array of values that spill into H5:K12. The third argument provides a default value to use when the formula runs into errors combining ranges, for example when ranges have different column or row counts. In the example below, the formula in cell C5 is: This is a custom function created with LAMBDA, based on several Excel functions, including INDEX, SEQUENCE, IFERROR, ROWS, COLUMNS, and MAX. Holding the whole thing together are LAMBDA and LET: This formula is based on a formula explained here, adapted to work with columns instead or rows. It’s a good example of how the LAMBDA function and LET function work well together. Inside the LET function, the first six lines of code simply assign values to variables. Once values are assigned, these variables drive the output of the function. The core logic of the formula, the code that builds the combined array, is here: This code can be tricky to read, especially if you’re new to LAMBDA functions and dynamic array formulas in general. With line breaks added for readability, it’s tempting to read it like a loop, with colindex as an incrementing counter, but colindex is not one value, but an array of 4 values, created with the SEQUENCE function earlier: Similarly, rowindex is an array of 8 numbers: The IF function tests the values in colindex all at once. If colindex is less than or equal to the count of the columns in range1 (2), INDEX fetches columns from range1. If the colindex is greater than 2, INDEX fetches columns from range2. In both cases, rowindex is used to retrieve rows. The array that IF and INDEX create is assigned to the variable result, which is returned as a final value by the formula through the IFERROR function. This is done as a way to catch errors that occur when ranges of different row or column counts are combined. In this case, INDEX will throw an error when it tries to get a value from a non-existent row or column, and the default value will be output instead of the error.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.