You want to display the Column references for a given search value in any column(s) within a given range. Values in the range are strings and any Row in any Column may be blank - that is, the data is not contiguous. The value of the column header indicates the relative column number within the data range.
PARAMETERS
Refer to the image and enter the values for:
- first Column of data (alpha value),
- last Column of data (alpha value),
- first Row of data (the header row),
- last Row of data.
- All ranges in the formula are automatically calculated based on these four values.
FORMULA
The formula is:
=join(", ",QUERY({TRANSPOSE(indirect(C3&C5&":"&C4&C6))},"Select Col1 where "&JOIN(" or ",ARRAYFORMULA("Col"&(COLUMN(indirect((C3&C5+1)&":"&address(C5+1,C6+C5,4,true)))-COLUMN(indirect(C3&5))+1)&" = '"&$B$2&"'"))))
LOGIC
Query Data Range
TRANSPOSE(indirect(C3&C5&":"&C6&C7))
- the data range (H4:AF99) is built from the parameters in cells C3, C4, C5 and C6 (refer snapshot)
- the data is inserted using
INDIRECT
- the data is transposed to that "Col1" contains the headers(the List#)
Where clause
where "&JOIN(" or ",ARRAYFORMULA("Col"&(COLUMN(indirect((C3&C5+1)&":"&address(C5+1,C6+C5,4,true)))-COLUMN(indirect(C3&5))+1)&" = '"&$B$2&"'"
- The purpose of this clause is to create a
where
condition like " where Col2 = 'ffff' or Col3 = 'ffff' or... Col96 = 'ffff'"
- Although there are only 25 Columns (H to AF) in the physical data, there are 96 Rows of data (including the header row).
- When the data is transposed (and rows become columns, and vice versa), there are 96 columns of data. "List#" occupies Col1, and data is in columns 2 to 96.
- Relative column numbers are generated by this snippet:
COLUMN(indirect((C3&C5+1)&":"&address(C5+1,C6+C5,4,true)))-COLUMN(indirect(C3&5))+1
- which resolves to something like:
- Column(H5:CY5)-Column(H5)-1
- when the
JOIN
function is added the outcome looks like this:
- " where Col2 = 'ffff' or Col3 = 'ffff' or... Col96 = 'ffff'"
- note the LAST column is #96
SAMPLE
- The data range in the sample is H4:AF99. Some columns and rows in the snapshot have been hidden
- The answer includes a value of "List25" because there is a value of "ffff" in Column 25 at row 99 (AF99).
- The purpose of this cell value is to confirm that the formula evaluates every cell in the data range.
- Other than the header, it is the only value in Column AF.