Search code examples
google-sheetsindexingfiltermatchvlookup

Google sheets - return the column number of a cell containing specific text


In Google Sheets, using formulae, is there a way I can return the column number of a cell that equals a specific string?

I often use the VLOOKUP formula, but find that I update and add columns in the target sheet over time. The result is that any VLOOKUP pointing at that sheet will return incorrect results because the index of the value to be returned is no longer correct.

So I'm looking for a formula I can use to return the index number in a VLOOKUP formula, which will always find the column index based on the title text of that column, e.g. "Email".

The formula would need to return the index of the cell that equals, not just contains, the search text, ie return the index of "Email" column, not the "Manager Email" column. The column titles will always be unique.

I found this question, but this returns the the whole cell reference, not just the index - I'm hoping there's a simpler solution to return just the column index by searching a single row (the first row) of a sheet for a cell containing the search text.


Solution

  • use:

    =MATCH("Email"; 1:1; 0)
    

    match string in row 1 if exact match

    also note that if you use this in Sheet2 you will need to use Sheet1!1:1