Do you want to lookup in any column and return the result? Something like this:

In this article, learn how to write necessary Excel formulas to get the result.
Data Setup for looking up in any column
You need to set up your data in below structure. One column with the data you want to get and multiple columns with potential lookup value. For example, team name in column C, member names in columns D:J, as depicted below.

Lookup formula:
Let’s say we want to lookup “Leonard”, who is in the tea “Geeky Group”. Here is the formula.
=XLOOKUP(1,BYROW(D5:J13,LAMBDA(row,COUNTIFS(row,"Leonard"))),C5:C13)
'notes:
'D5:J13 contains team member names
'C5:C13 contains team names
'this will return #N/A if none of the teams contain lookup value - ie Leonard
How does this formula work?
To understand how this lookup in any column formula is working, we need to first understand a few Excel concepts.
- BYROW: This function let’s you define logic or operations that apply consistently for each row of the data. As we want to look in each row of team members and see if any of them is “Leonard”, BYROW is perfect for this operation.
- LAMBDA: We can use Excel’s LAMBDA functions to create custom logic. As we need to check each row of the data to see if any of the members are “Leonard”, I created a LAMBDA to do that operation. LAMBDA(row, COUNTIFS(row, “Leonard”)) will return the count of “Leonard” in the input variable row
So now that you have the basic concepts ready, let’s understand the lookup in any column function. Here is the formula again.
=XLOOKUP(1,BYROW(D5:J13,LAMBDA(row,COUNTIFS(row,"Leonard"))),C5:C13)
'notes:
'D5:J13 contains team member names
'C5:C13 contains team names
'this will return #N/A if none of the teams contain lookup value - ie Leonard
- BYROW(D5:J13,LAMBDA(row,COUNTIFS(row,”Leonard”))): This formula portion tells us how many times “Leonard” appeared in each row of the data. It will be 0 if the team doesn’t contain lookup value and 1(or more) if the team contains the lookup value. For our sample data, this would be {0;0;0;0;0;1;0;0;0}
- XLOOKUP(1, BYROW(…), C5:C13): Now that we know which team has the lookup value (Leonard), we just lookup for 1 (count) in the BYROW output and return the corresponding team name from the column C.
What if there are multiple matching values?
By default XLOOKUP returns the first matching value whenever we have multiple matches. If you want to see all team names for a given person name (for example Amy is in two teams – “Geeky Group” and “99 Not Out”.

In this case, we can use FILTER() function instead of XLOOKUP.
Using FILTER function to return all matching values
Here is the formula to see all team names for a given person.
=FILTER(C5:C13,BYROW(D5:J13="Amy",OR))
'notes:
'D5:J13 contains team member names
'C5:C13 contains team names
'Here we are using an advanced variation of BYROW that applies OR operation on every row of comparison directly. The end result would be a bunch of TRUE or FALSE values, TRUE for teams that contain "Amy" and FALSE for rest of the rows.
This formula uses an advanced variation of the BYROW by doing a comparison directly and applying OR operation on each row of comparison. The result of BYROW would be an array of TRUE or FALSE values. TRUE for rows which contain Amy and FALSE for the rest.
When FILTER(C5:C13 …) sees this array of TRUE/FALSE values, it would return the matching items from C5:C13 for all TRUE values.
In this case, the output is shown below.

Further reading:
If you want to understand how the inner parts of this formula are working, refer to below articles / videos.
- How to use XLOOKUP function in Excel
- BYROW explained with examples
- What is LAMBDA function in Excel
- How to use FILTER function in Excel
- FILTER function in Excel – Video
Limitations of both formulas
Both of the above approaches (XLOOKUP and FILTER) only work with Excel 365 as BYROW is only available in that version of Excel. If you are using an older version of Excel (such as 2024, 2019 or 2016) you can’t use these approaches.
Alternative formula for older version of Excel
There is no alternative for the FILTER() approach as older versions of Excel are not capable of spilling values. But there is an alternative to XLOOKUP() approach of returning the first matching value by looking up any column.
Here is the formula:
=INDEX($C$5:$C$13,MATCH(1, MMULT((D5:J13="Leonard")*1,TRANSPOSE(COLUMN(D5:J13)^0)),0))
'notes:
'D5:J13 contains team member names
'C5:C13 contains team names
Using MMULT to mimic BYROW operation
Most of the above formula is easy to understand, but the bit with MMULT is the confusing part. So let me explain. Here is the MMULT portion: MMULT((D5:J13=”Leonard”)*1,TRANSPOSE(COLUMN(D5:J13)^0))
- (D5:J13=”Leonard”) checks every cell of the team member data and returns a bunch of TRUE or FALSE values. TRUE when the cell value is “Leonard” and FALSE otherwise. This is how that output looks like:

- (D5:J13=”Leonard”)*1 turns this boolean array into a bunch of 0s & 1s (0 = false and 1 = true). So the output at this point would be:

- COLUMN(D5:J13) would return the the column numbers for columns D to J. This would be an array of {4,5,6,7,8,9,10}
- TRANSPOSE(COLUMN(D5:J13) turns these numbers into a row-wise array. So the net result at this point is {4;5;6;7;8;9;10}
- TRANSPOSE(COLUMN(D5:J13)^0 takes all these numbers and makes them 1s as any number raised to the power of 0 would be. We just need a row-wise array of 1s same size as the number of columns in the team member array. So this is a long-winded way of getting there as older versions of Excel don’t have SEQUENCE formula. At this stage, our second part of MMULT operation has this array: {1;1;1;1;1;1;1}
- Now, MMULT just multiplies these two matrices. Here they are again:

- When the matrix multiplication is done, we end up with a vertical (row-wise) array of 0s and 1s. 0 when the row doesn’t contain the lookup value (Leonard) and 1 otherwise. The result of this multiplication is:

Let’s put everything together
So now that we know how the MMULT magic is working, let’s put all the pieces together.
=INDEX($C$5:$C$13,MATCH(1, MMULT((D5:J13="Leonard")*1,TRANSPOSE(COLUMN(D5:J13)^0)),0))
'notes:
'D5:J13 contains team member names
'C5:C13 contains team names
INDEX($C$5:$C$13,MATCH(1, MMULT(…), 0)) simply looks for a 1 in the MMULT result and returns the corresponding value from range C5:C13.
Further reading on older Excel formulas:
Please refer to below pages for further learning on these formula techniques.
- INDEX + MATCH formula in Excel – explanation
- SUMPRODUCT explained
- How to use boolean operations with arrays in Excel
- MMULT examples
Example Workbook: Lookup in any column
If you need a practice file to understand these formulas better, download it here.
In conclusion
While Excel’s lookup functions (XLOOKUP, VLOOKUP, FILTER, INDEX+MATCH) are great, they all suffer from one nagging limitation. They can only lookup in one place at a time (ie one column or row). But most of the time, our business data is not so tidy. We get data that can span multiple columns. In such cases, using the BYROW() to process one row at a time and then applying lookup or filter logic is a great alternative.
Moreover, if your data is structured vertically (ie team members are listed in rows instead of columns), we can use the same approach with BYCOL function. It applies the logic by column.
The BY functions (BYROW and BYCOL) are great addition to Excel and should be part of every analyst’s toolkit. Using them solves many tricky data problems easily.